On 04/12/12 08:47, Marcin Szamotulski wrote:
On 07:57 Wed 11 Apr     , Jürgen Krämer wrote:
this won't work if you give a count, e.g. "3<C-J>", because the count is
only applied to the first command in the mapping. Better define the
mappings like

   vnoremap<expr>  <c-j>  'jo'.v:count1.'jo'
   vnoremap<expr>  <c-k>  'ko'.v:count1.'ko'

or

   vnoremap<c-j>  @='jojo'<cr>
   vnoremap<c-k>  @='koko'<cr>

Can you explain (or give :help hint) how @= works here that makes the trick.

It's using the expression register as the source of the executed macro. So a prefixed count is the number of times the macro is executed, rather than the number of times the first "j" or "k" is executed (where the second one, without the "v:count1" as Jürgen uses in his first example, has a default count of 1). So using the expression register would be like recording "jojo" into a register, and then playing it back with an optional prefixed count.

I rarely see the expression register used for macros (I've used them for fun, and once or twice it's saved me a keystroke in VimGolf), but it's nice to see an occasion where it's actually useful.

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to