Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If Vim command-line is being edited and the Vim instance receives a string due to vim --remote-send KEYS executed on a shell somewhere, result is somewhat equivalent to pressing Return in the command-line and typing the received KEYS afterwards. Since the command that is unintentially executed can be hard to recover (an artificial example could be !rm -rf *), is there a way to prevent this behavior?

Initial idea was to send e.g. <Esc><Esc>KEYS to discard any possible active input in the receiving Vim instance. This does quit a potentially active Insert mode and prevents KEYS landing in the current buffer. But this is does not work for the command-line input.

I was thinking of some autocommand-event to trigger user confirmation upon remote keys receipt, but none of available events looked right for the case.

share|improve this question
up vote 5 down vote accepted

One solution (not perfect) is to use Ctrl-C instead, for example:

vim --remote-send '<c-c>:echo "test"<cr>'

This seems to work in command-line, normal, insert and visual mode, but not in operator-pending mode (at least in my test, after pressing va from normal mode with no timeouts).

share|improve this answer
This solves indeed the problem of unintended command executions. Concerning your example with va, sending just <c-c> first, followed by <c-c>KEYS puts Vim back to Normal mode and interpret KEYS as expected. – meekreau Feb 20 at 20:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.