I have functions that move my cursor to normal mode, for example:
function! S: Execute (distance, direction) execution "normal!". String (a: distance). A: direction endfunction
where a: distance
is an integer and a: direction
is something like 'h'
or 'l'
. It works fine as a normal mode mapping, however, I want to extend these motions in visual mode.
The problem is that execute "normal ... etc ..."
run commands while not working in view mode (i.e., the cursor does not consider movement as normal As if choosing the text between the original and the last cursor positions). A work can be done around: Exit Visual Mode, drop a mark, execute skip ()
and then select from the new cursor position to the mark. I do not care about this solution not only because it requires an icon, but it does not "feel" correctly to convert normal mode movements into movements of visual mode.
Any suggestions? I should say that I have many functions like skip ()
execute execute "normal ... movement ..."
, so it should be a general rule
Pass current mode in function (like Via a isvisual
flag); Know your mapping mode, or you can query mode ()
for it, then for the visual mode, usually select the current selection with live
(As you were missing selection when triggering your function from mapping).
function! S: Exclude (distance, direction, isVisual) executed "normal!" (A: isvisual? 'Gv': '') A: Distance A: Direction endfunction
This will leave the selection (expanded) after your visual mode mapping. Note that live
restores the cursor to a selection border (usually end); You may need an account for this / switch to the other side (with o
).
Comments
Post a Comment