Why do some Vim mappings include <C-U> after a colon?

I'm trying to figure out the syntax of the mapping commands, like onoremap, in vim.

Specially, I am confused over this line in the manual, regarding the use of <C-U>:

The CTRL-U (<C-U>) is used to remove the range that Vim may insert.

Can someone explain this?


That isn't part of the syntax for the onoremap command, that is explaining what a particular mapping does. That mapping is:

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

So, when the F key is used while an operator is pending vim will replace that with the bits in the next argument to the onoremap command. That starts with a : to begin an ex mode command. If there is a visual selection when the mapping is used, vim will automatically insert the range '<,'> so that the following ex command will apply to the visual selection, leaving the command line looking like:

:'<,'>

The <C-U> in the mapping tells vim that after the : is entered the Control+U combination should be used to clear the command line, eliminating the automatically inserted range leaving the command line looking like:

:

Then the remainder of the mapping is used.

You can see this for yourself by using V to begin a line-wise visual selection, then : to start entering a command. The range will show up, you can then use Control+U to clear it just as the example mapping does.

The portion of vim help that contains that mapping explains the remainder of it.


The Ctrl-U Vim-map operates as the same short-cut from the terminal command line. Check: https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/

Avoid remapping few of them (like which breaks out a process on a terminal), but the majority (like Ctr-A or Ctrl-X) can be remapped. If your VIM is no terminal one (like gVim), you can remap them all inconsiderately.

Btw: Ctrl-Shift-Letter is like Ctrl-Letter map for VIM-terminal.

Some terminal short-cuts:

  " 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