How and why to exit from the Insert Mode of gVim without pressing the ESC key
This article was written specifically for the graphic version of Vim, ie for gVim.
I use gVim about every day and every time I need to write more than some words.Vim is fast, light, mind friendly, really efficient.
I like to find any solution to improve my gVim experience to get the best results in the less time considering that I hardly ever look at the keyboard when I write (my past as a pianist helps me!).
One of the problems I have to solve is the exit from the Insert Mode.
The <ESC> key: a fundamental in Vim and gVim
One of the Vim and gVim fundamental is the <ESC> key.
You read in vimtutor and other tutorials that the canonical way to exit from insert mode is to press the <ESC> key.
That’s true. But the <ESC> key is at the edge of the keyboard, far from the center of it. Then when you need to exit frequently from the insert mode it could be a little uncomfortable.
The built-in alternative: <Ctrl-c>
There’s a built-in alternative. You can use, without any configuration, the combination of two keys:<Ctrl-c>.
But even this solution is not much more comfortable than the fundamental, because the “c” key is not particularly in evidence inside the keyboard and you often need to take a look to the keyboard itself to press the right key.
You must also control than the permanent shift key is not activated.
Then if you need to frequently exit from the insert mode, this is not the best solution.
The “jj” solution
Another solution could be to use a quick repetition of the same key.
The “j” key is perfect for this purpose because this key is in the center of the keyboard and you can easily find it without using your eyes thanks to its tactile feedback.
Have you noticed that the “f” and “j” keys have a relief notch that any other key doesn’t have?
Then you can easily configure your .vimrc file to generate a virtual <ESC> by quickly pressing the “j” key twice. You have just to add the following text string in it:
imap jj <Esc>
It may seem the ideal solution but after a while, it can create some small delay because in some situations you must lose a few fractions of time to point the left index finger to the “j” and especially because you must always remember to check that the permanent shift key is not activated.
The double <SPACE> solution
A key immediately reachable without any delay, that’s also “shift/key” independent is the <SPACE> one.
I tried to apply the same previous solution to the<SPACE> key entering the following string in the configuration file:
imap <SPACE><SPACE> <Esc>
It works! But remains a small problem: every time trying that you press the <SPACE> you have a little delay because gVim waits some milliseconds for the repetition configured in .vimrc: if you twice press the <SPACE> into the delayed time you get the <ESC> key, therefore you get another space into the document that you are editing.
It’s not yet the solution I was looking for.
My favorite solution (at the moment): <CTRL> <SPACE>
To avoid the SPACE lag with another upper/lower case independent solution you can use the keys combination <CTRL + SPACE>:
imap <C-SPACE> <Esc>
Now you can easily and quickly exit from the insert mode without losing time to see the keyboard and even if you have activated the permanent shift key, by pressing the combination <Ctrl+Space>.
The <jj> and <Ctrl+Space> configurations could coexist and you can use one or the other at your choice.
For the moment I think I have found the most convenient and fastest way to exit the insert mode.
But if someone had any other solution to propose I would be very happy to try it.
Thanks for your attention.
Originally published at Medium.com
Comments
Post a Comment