Vim – Exiting Block Insert Mode with Ctrl-C

vim

In vim, if you are in block insert mode (Ctrl-V, Shift-I) and exit using Ctrl-C (instead of Esc), it cancels the block edit (and only edits the first row).

Why is this? In almost all other contexts, Ctrl-C and Esc are synonymous. (And ideally there's a way to fix this — I've now gotten used to doing Ctrl-C and it would be a shame if I had to relearn…)

Best Answer

Ctrl-c and Esc are not guaranteed to be synonymous, and often differ. For example, in Insert mode, Esc will trigger abbreviations and go to Normal mode, whereas Ctrl-c will not trigger abbreviations nor the InsertLeave autocommand and go straight to Normal mode. Another example is in the old vi command line mode, Esc would actually execute the command as if you had hit Enter. Vim deliberately changed this because that behavior was deemed unintuitive and surprising, but you can still enable it by adding x to 'cpoptions'.

As for the blockwise visual operators, the blockwise-operators help tag has the following documentation:

Visual-block Insert                     *v_b_I*
With a blockwise selection, I{string}<ESC> will insert {string} at the start
of block on every line of the block, provided that the line extends into the
block.  Thus lines that are short will remain unmodified.  TABs are split to
retain visual columns.

Notice that only Esc is mentioned, not Ctrl-c.

So, no, Ctrl-c and Esc are not equivalent. It is never a shame to disabuse oneself of a misconception. Once you have realized that, you can decide what to do next. Immediately obvious options are to learn the differences and use the correct key, or decide that you don't need the functionality of one of the keys and remap it to match the other.

Related Question