在这个答案中,我面对在CTRL-U之后和实际函数名称之前在函数调用中使用的:

:nnoremap <buffer> <cr> :<C-U>call append('.', repeat([''],v:count1))<cr>


以下是帮助内容:

CTRL-U      Scroll window Upwards in the buffer.  The number of
            lines comes from the scroll option (default: half a
            screen).  If [count] given, first set the 'scroll'
            option to [count].


我自己尝试过,并且按预期工作。但是我不太了解有关scroll选项的部分。它们是什么意思?

此外,它在插入模式下还会做一些奇怪的事情。据我了解,它会删除从光标到该行开头的所有内容,然后将结果行与上面的行连接起来。

#1 楼

默认情况下,“帮助”返回适用于普通模式的所有映射。在正常模式下,<C-u>确实会向上滚动,但这不是我们感兴趣的。要查看<C-u>在命令行模式或cmode(以冒号开头键入命令的模式)下的功能,请搜索:h c_CTRL-u

                            *c_CTRL-U*
CTRL-U      Remove all characters between the cursor position and
        the beginning of the line.  Previous versions of vim
        deleted all characters on the line.  If that is the
        preferred behavior, add the following to your .vimrc: >
            :cnoremap <C-U> <C-E><C-U>


要了解为什么这对于正常模式映射很有用,请尝试将其删除,尝试键入类似5:的内容,然后看看会发生什么。您应该看到类似以下内容的内容:

:.,.+4


这是一个范围

现在尝试输入5:<C-u>看看会发生什么。您应该只看到

:


类似地,在可视模式下,按:会插入范围

:'<,'>


这就是为什么您会经常看到如下映射:

nnoremap foo :<C-u>bar




xnoremap foo :<C-u>bar