Vim:使计数功能只运行一次

时间:2016-06-02 20:15:11

标签: vim

我有这个功能:

function Test()
    echom "call " . v:count
endfunction
nnoremap a :call Test()<cr>

如果我输入,请说4a,它会打印出来

  

致电4
  致电4
  致电4
  致电4

但是,当我使用计数时,我希望它只执行一次。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

在调用函数之前需要<C-U>

function Test()
   echom "call " . v:count
endfunction
nnoremap a :<C-U>call Test()<cr>

<C-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>