I have some text selected in select mode. I want to delete it and start insert-mode completion.

When I type these keystrokes into Vim it works perfectly:


gv switches to visual mode; c changes / cuts the selection and switches to insert mode; and the rest triggers insert-mode completion.

However when I try to this from Vimscript it doesn't work:

execute "normal! gvc\<C-X>\<C-U>"

The gv part works but the c cuts a character extra at the right hand end of the selection, and the cursor ends up one character before where I want it (in insert mode, which is correct), and the completion doesn't start.

For example, if bar is selected in the following line:

foo(bar, baz

– then after my execute "normal! ..." I am left with:

foo( baz

– with the cursor just before the bracket. What I want is foo(, baz with the cursor just after the bracket and the completion menu open.

How can I get this working via Vimscript?

  • Why do you need execute? Try normal! gvc<C-X><C-U>. – D. Ben Knoble Jun 18 '19 at 19:43
  • You need it so you can escape the key sequence; without it you get the literal text <C-X><C-U> inserted. See :help expr-quote. – Andy Stewart Jun 19 '19 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.