45

我正在尝试找出映射命令的语法,例如onoremapvim 中的 。

特别是,我对手册中的这一行感到困惑,关于使用<C-U>

CTRL-U ( <C-U>) 用于删除 Vim 可能插入的范围。

有人可以解释一下吗?

4

2 回答 2

65

这不是onoremap命令语法的一部分,它解释了特定映射的作用。该映射是:

onoremap <silent> F :<C-U>normal! 0f(hviw<CR>

因此,当在F操作符挂起时使用密钥时,vim 将用onoremap命令的下一个参数中的位替换它。以:开始ex模式命令开始。如果在使用映射时有视觉选择,vim 将自动插入范围'<,'>,以便将以下ex命令应用于视觉选择,使命令行看起来像:

:'<,'>

映射中的<C-U>告诉 vim 在:输入之后应该使用Control+组合来清除命令行,消除自动插入的范围,使命令行看起来像:U

:

然后使用映射的其余部分。

您可以通过使用V开始逐行视觉选择,然后:开始输入命令来亲眼看到这一点。范围将显示出来,然后您可以使用Control+U清除它,就像示例映射一样。

包含该映射的 vim 帮助部分解释了它的其余部分。

于 2012-12-12T02:10:14.420 回答
1

Ctrl-U Vim-map 的操作与终端命令行的相同快捷方式相同。检查:https ://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/

避免重新映射其中的少数(例如在终端上中断进程),但可以重新映射大多数(例如 Ctr-A 或 Ctrl-X)。如果您的 VIM 不是终端设备(如 gVim),您可以不加考虑地重新映射它们。

顺便说一句:Ctrl-Shift-Letter 就像 VIM 终端的 Ctrl-Letter 映射。

一些终端捷径:

  " copy-paste 
    " <C-S-c> copy
    " <C-S-v> paste (or replace visual selected)
  " manage running processes
    " <C-c>   break out of a command or process on a terminal. This will stop a running program immediately.
    " <C-z>   send a running program in the background
    " <C-d>   If you are using an SSH connection, it will be closed. If you are using a terminal directly, it will be closed
  " control what appears on the screen
    " <C-l>   clear terminal screen 
    " <C-s>   Stop all output to the screen. This is particularly useful when running commands with a lot of long, verbose output, but you don’t want to stop the command itself with Ctrl+C.  
    " <C-q>   Resume output to the screen after stopping it with Ctrl+S.
  " Moving the Cursor
    " <C-a>   or Home: move cursor to beginning of line 
    " <C-e>   or End:  ""             end       ""         
    " <C-xx>   Move between the beginning of the line and the current position of the cursor. This allows you to press Ctrl+XX to return to the start of the line, change something, and then press Ctrl+XX to go back to your original cursor position. To use this shortcut, hold the Ctrl key and tap the X key twice.
    " <A-b>   go left 1 word 
    " <C-b>   ""        char (like left-arrow) 
    " <A-f>   go right 1 word 
    " <C-f>   ""         char (like right-arrow) 
  " Cutting and Pasting
    " <C-u>   erases everything from the current cursor position to the beginning of the line
    " <C-k>   erases everything from the current cursor position to the end of the line
    " <C-w>   erase the word preceding to the cursor position. If the cursor is on a word itself, it will erase all letters from the cursor position to the beginning of the word.
    " <C-y>    paste the erased text that you saw with Ctrl + W, Ctrl + U and Ctrl + K shortcuts  
  " Deleting Text
    " <C-d>    or Delete: Delete the character under the cursor
    " <A-d>    Delete all characters after the cursor on the current line.
    " <C-h>    Backspace: Delete the character before the cursor.
  " Fixing Typos
    " <A-t>   Swap the current word with the previous word.
    " <C-t>   Swap the last two characters before the cursor with each other. You can use this to quickly fix typos when you type two characters in the wrong order.
    " <C-_>   Undo your last key press. You can repeat this to undo multiple times.
  " Capitalizing Char
    " <A-u>   Capitalize every character from the cursor to the end of the current word
    " <A-l>   Uncapitalize every character from the cursor to the end of the current word
    " <A-c>   Capitalize the character under the cursor. Your cursor will move to the end of the current word.
  " Command History
    " <C-p>    like up-arrow: press it repeatedly to keep on going back in the command history 
    " <C-n>    like down-arrow: use this shortcut in conjugation with Ctrl+P. Ctrl+N displays the next command 
    " <A-r>    revert any changes to a command you’ve pulled from your history if you’ve edited it.
    " <C-r>    search in your command history. Just press Ctrl+R and start typing. If you want to see more commands for the same string, just keep pressing Ctrl + R.
    " <C-o>    Run a command you found with Ctrl+R  
    " <C-g>    Leave history searching mode without running a command
于 2020-08-01T23:02:44.850 回答