为什么一些Vim映射包括冒号后的<c-u>?</c-u>

时间:2012-12-12 00:33:19

标签: syntax vim

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

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

  

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

有人可以解释一下吗?

2 个答案:

答案 0 :(得分:38)

这不是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帮助部分解释了其余部分。

答案 1 :(得分:0)

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