Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

syntax - 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?

question from:https://stackoverflow.com/questions/13830874/why-do-some-vim-mappings-include-c-u-after-a-colon

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...