3

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.

1 Answer 1

4

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).

1
  • 1
    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, 2016 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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