vim - How to call a function that moves the cursor without leaving visual mode? -
i have function moves cursor built-in cursor() function , works fine on normal mode.
concreteness suppose function:
function! f() call cursor( line('.')+1, 1) endfunction used mappings as:
nnoremap <buffer> :call f()<cr> now want reuse function move cursor on visual mode (visual, line visual, , block visual) , without losing previous selection.
for example, initial buffer in visual mode (c means cursor @ line, v means line part of current visual selection):
vc 1 2 3 hitting a give:
v 1 vc 2 3 and hitting a again give:
v 1 v 2 vc 3 so old selection kept.
i reuse f() as possible, since in application f() quite large.
best way that?
up now, best use wrapper function:
function! vismove(f) normal! gv call function(a:f)() endfunction and map as:
vnoremap <buffer> :call vismove('f')<cr> however not satisfied because this:
- it requires putting annoying wrapper on every new fgplugin write.
- calling function moves cursor (or has other arbitrary side effects) without ever leaving visual (current) mode seems such natural thing able do. there
<expr>it, resets cursor position.
i solve passing mode argument (or alternatively boolean isvisual flag) function:
fu! f(mode) range if a:mode ==# 'v' normal! gv endif ... endf nn <buffer> :cal f('n')<cr> vn <buffer> :cal f('v')<cr>