On Oct 16, 2:16 am, Dewr <[email protected]> wrote:
> keymapped functions repeat when it called while vim is selecting a text
> block.
>
> I have tested with this code.
> *<code>
> function foobar()
> echo "foobar!"
> endfunction
> map <F5> :call foobar()<CR>
> </code>*
>
> I could avoid this by adding ^[ (=esc) at the head of key-mapping command.
>
>From :help :call you can see:
When a range is given and the function doesn't handle it
itself, the function is executed for each line in the range,
with the cursor in the first column of that line.
Now, combine that with the knowledge that :map takes effect in visual
mode, and that pressing ':' in visual mode causes the command-line to
be pre-populated with :'<,'> (a range starting on the first line of
the selection and ending on the last), you can figure out what's going
on.
When you press <F5> in visual mode, what you really execute is:
:'<,'>call foobar()<CR>
This will call foobar() once for each line you have selected.
To get around this, you need to use mode-specific mappings instead:
nmap <F5> :call foobar()<cr>
vmap <f5> :<c-u>call foobar()<cr>
The <C-U> is to get rid of the pre-populated '<,'> on the command
line. See :help c_CTRL-U
This will also work, as you noticed:
vmap <F5> <ESC>:call foobar()<CR>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---