How to execute visual mode commands from a Vim function?

I have a function that takes a string of commands to execute and ensures that 'paste' enabled before running them. What I'm looking for is like the following:

 vmap <silent> <CK> :<CU>call InPasteMode("<Plug>ReplaceVisual")<CR> function! InPasteMode(command) let oldpaste = &l:paste try set paste execute "normal" a:command finally let &l:paste = oldpaste endtry endfunction 

but the "<Plug>ReplaceVisual" should run in Visual mode, and not in normal mode.

Is there a command like :normal that launches keystrokes in visual mode?

+4
source share
1 answer

gv restores the last visual selection. So, something like execute "normal gv" . a:command execute "normal gv" . a:command should work.

+8
source

Source: https://habr.com/ru/post/1340875/


All Articles