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:

  1. it requires putting annoying wrapper on every new fgplugin write.
  2. 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> 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -