Why do some Vim mappings include CTRL_U after a colon?

本文详细解释了Vim中为何某些映射会包含冒号,以及如何通过映射实现特定的功能,例如在视觉选择模式下使用F键启动一系列命令。文章深入探讨了Vim映射的语法和工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Why do some Vim mappings include after a colon?

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.

vim做映射时使用做前缀的原因

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值