Vim Tips Wiki
Advertisement
Tip 787 Printable Monobook Previous Next

created September 12, 2004 · complexity intermediate · author Luc St-Louis · version 5.7


Suppose you have a function requiring a count argument, and you would like to be able to invoke it with a mapping, and also allow the count to be prefixed to the mapping, like you can with for example {count}CTRL-^ (to edit the [count]th file in the buffer list).

Here is an example of code that can be used to call a Foo() function with such a prefix count argument. All it shows is the structure required for such a thing to work (well, it's the best the author of the tip was able to come up with). Given the following, typing 42,a will echo FOO: 42:

function! Foo(count)
  echo 'FOO: ' . a:count
endfunction

command! -nargs=1 FooCmd call Foo(<args>)
map ,a :<C-U>FooCmd(v:count)<CR>

References


Advertisement