2

I've started using CTRL+C instead of ESC in vim because of its position on the keyboard and better responsiveness. It mostly behaves the same except when exiting visual block replacements.

I am hoping someone can explain why and possibly propose a fix/workaround.

Consider the following:

<C-v>jjjsmy replacement text<ESC>

versus

<C-v>jjjsmy replacement text<C-c>

With ESC, my replacement text appears on all 4 lines. With CTRL+C, my replacement text only shows up on the first line. What is going on here?

5

At first they might do the same but internally they are interpreted differently. In layman's terms they mean something like this:

  • Esc: "OK I am done (with whatever I was doing)."
  • CTRLC: "Stop that as fast as possible!"

It is not clearly documented (as far as I can see) but there are some indications:

  • i_<esc> says "End ... mode" whereas i_CTRL-C says "Quit insert mode"
  • i_CTRL-C does not expand abbreviations and does not fire the InserLeave autocommand.
  • Sadly v_CTRL-C and ì_<Esc> are less clear, both say "quit".
  • When you are in block insert mode (like in the question) you only see the characters you type on the first line. Only later when you finish (with Esc) will the text appear in the other lines. And CTRLC seems to "abort" before that.
  • You might know CTRLC from the shell where it sends SIGINT which normally terminates a command.
  • 1
    True. Taking that further, :h i_CTRL-c says ...does not trigger the InsertLeave autocommand event. Maybe InsertLeave is what triggers {Visual}s to finish? Doesn't really say. Maybe I can rig it so that the InsertLeave event happens even with <C-c>. – Lombard Jul 22 '18 at 21:02
  • you say ctrl-c gives "better responsiveness," but this is the real problem. escape or ctrl-[ should happen immediately. if it doesn't something else is wrong with your config – Mass Jul 22 '18 at 21:25
  • 2
    @Mass I had always assumed that the delay was because Vim needs to wait to make sure my Esc (or c-[) is not part of an escape sequence (e.g. arrow keys). How does one configure around that? Note: this only affects terminal vim. – Lombard Jul 22 '18 at 21:37
  • 2
    @Lombard ttimeoutlen will let you configure the length of the delay. In Vim it defaults to 100ms, but you could safely drop it to 50ms (Neovim default) or lower. – ZeroKnight Jul 22 '18 at 21:46
  • 1
    @lombard, @zeroknight is correct, except if you have a vimrc it actually defaults to 1000ms (one second). if you do set ttimeout ttimeoutlen=50 you should see a big improvement – Mass Jul 22 '18 at 22:43

Your Answer

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

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