Reputation: 5658
I have this function:
function Test()
echom "call " . v:count
endfunction
nnoremap a :call Test()<cr>
If I type, let's say 4a
, it will print out
call 4
call 4
call 4
call 4
However, I want it only to be executed once, when I use a count. How can I achieve that?
Upvotes: 0
Views: 45
Reputation: 4212
You need <C-U>
before calling the function.
function Test()
echom "call " . v:count
endfunction
nnoremap a :<C-U>call Test()<cr>
<C-U>
removes all the characters before the cursor on command line. From help:
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>
Upvotes: 2