Vim Tips Wiki
m (A mapping that invokes a function with a count prefix. moved to Invoke a function with a count prefix: Page moved by JohnBot to improve title)
(Fix double-brace ending tip template + clean)
Line 3: Line 3:
 
|id=787
 
|id=787
 
|title=A mapping that invokes a function with a count prefix.
 
|title=A mapping that invokes a function with a count prefix.
|created=September 12, 2004 10:34
+
|created=September 12, 2004
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Luc St-Louis
 
|author=Luc St-Louis
Line 9: Line 9:
 
|rating=4/7
 
|rating=4/7
 
|text=
 
|text=
  +
}}
The following mapping echoes <tt>Foo: 42</tt> when one types <tt>42,a</tt>.
 
function! Foo(count)
 
echo 'Foo: ' . a:count
 
endfunction
 
 
command! -nargs=1 FooCmd call Foo(&lt;args&gt;)
 
 
map ,a :&lt;C-U&gt;FooCmd(v:count)&lt;CR&gt;
 
   
 
The following mapping echoes <tt>Foo: 42</tt> when one types <tt>42,a</tt>.
This code snippet took me a lot of time to work out correctly. If you don't write much Vim scripts, it will be pretty much useless to you. But if you do, I hope you will appreciate the distilled information it embodies. }}
 
  +
<pre>
 
function! Foo(count)
 
echo 'Foo: ' . a:count
 
endfunction
  +
 
command! -nargs=1 FooCmd call Foo(&lt;args&gt;)
 
map ,a :&lt;C-U&gt;FooCmd(v:count)&lt;CR&gt;
  +
</pre>
  +
 
This code snippet took me a lot of time to work out correctly. If you don't write much Vim scripts, it will be pretty much useless to you. But if you do, I hope you will appreciate the distilled information it embodies.
   
 
==References==
 
==References==
Line 24: Line 27:
   
 
== Comments ==
 
== Comments ==
Could you please explain in slightly greater detail what this code does and where it can be generally used??
+
Could you please explain in slightly greater detail what this code does and where it can be generally used?
   
'''Anonymous''', September 17, 2004 3:31
 
 
----
 
----
<!-- parsed by vimtips.py in 0.471296 seconds-->
 
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Revision as of 04:59, 21 October 2007

Previous TipNext Tip

Tip: #787 - Invoke a function with a count prefix

Created: September 12, 2004 Complexity: intermediate Author: Luc St-Louis Version: 5.7 Karma: 4/7 Imported from: Tip#787

The following mapping echoes Foo: 42 when one types 42,a.

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

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

This code snippet took me a lot of time to work out correctly. If you don't write much Vim scripts, it will be pretty much useless to you. But if you do, I hope you will appreciate the distilled information it embodies.

References

Comments

Could you please explain in slightly greater detail what this code does and where it can be generally used?