Why arrow keys are not recommended in Vim

"Never use arrow keys in Vim!"

I heard this from a random speaker, but didn't have the chance to ask him why. Also, if you don't use the arrow keys, how can you move the cursor in the Insert mode?


Using the arrow keys is considered a bad habit, because if you're using the arrow keys you're probably missing out on many of vim's lovely features.

When people first start to use vim, they tend to stay in insert mode since this is more like conventional text editing. To be effective in vim however, you should only be in insert mode when you're actually entering text. If you want to move the cursor around, you should be in normal mode. You should pretty much be in normal mode by default.

In normal mode there are a million shortcuts for moving around. You can use hjkl to move around one space at a time, or you can move by words, paragraphs and so on. If you're in normal mode, there's no point in using the arrow keys instead of hjkl since they're further away.

There's the attitude that if you're using the arrow keys, you're using vim "wrong". The truth is that vim has a really really steep learning curve, so while you're learning do whatever keeps you sane. When I first started using vim I did everything the "wrong" way and I didn't have any problems breaking the habits once I learned more of vim's commands.

As an example, when I first started, say I wanted to change the text in quotes:

String mystring = "I want to change this";

I would go into insert mode, move to the end of the string using the arrow keys, press backspace until the string was gone, and enter the new text.

A much better way is to put your cursor anywhere in the string (normal mode), then press ci". This will change in ". It will delete everything between the quotes and put you into insert mode so that I can enter the new text.


Key Placement

In short, Vim uses the hjkl keys as the navigation interface is because it's a remnant of the old "ADM-3A" terminal, that had these keys marked with arrows.

Keyboard

Since vim is derived from vi, it uses the same hjkl keys.

New Habits

The letter based replacement for the arrow keys allows you to navigate the text without taking your hands away from standard typing configuration. This is arguably more efficient and faster than moving your hand to hit the arrow keys. As outlined in reference #2 (see resources) this is not the end of the advantages to this: VIM has a lot of other shortcuts that you can access without moving your hands.

Resources and Insert Mode

There are a few very detailed and accurate answers to the 2 parts of your question: in terms of arrow key replacement, I have answered in a quick and summary manner, however for your insert question, please see the resources listed below.

  • You can read more on key placement here.
  • You can read about moving the cursor during insert mode here.

That stupid mantra is often repeated by touch-typists for whom the home row is like a second spine or by non-touch-typist who want to look cool. For non touch-typists, the home row is simply not that special and slightly moving the right hand to reach the arrows is not a problem at all.

What is important to consider is what the people who repeat that mantra propose to use instead.

Most of the time, they insist on using hjkl.

If we leave out the fact that these keys are only used because the keyboard used by vi's author didn't have physical arrow keys and thus that any argument against the arrow keys is just rationalization, hjkl are only marginally better than the arrows anyway. Yes, the only benefit of using hjkl over the arrows is that you skip that small movement of the right hand to and from the arrows. Whether that benefit is worth the trouble is your call.

But that movement of the right hand is not why using only the arrows is inefficient. It is inefficient because they restrain you to move character-by-character and line-by-line while most of the movement needed for editing text have a much larger range.

Hammering the right arrow 13 times is inefficient and boring. Is it that better to hammer the l key 13 times? No. It's equally stupid.

Keeping the right arrow pressed until you reach your target is less boring but it's error-prone and almost as inefficient as 13 hits because of the necessary and non-deterministic slow down at the end. Is it that better to keep the l key pressed? No. Of course not.

Thankfully most GUI toolkits provide combos like Ctrl+Right that allow us to move word-by-word or jump to EOL, to next paragraph or whatever. These shortcuts help us navigate a lot faster and more intelligently than with single arrows. Do we have the same with hjkl? No, we don't. We can use a count, if we want, but who wants to count characters for every motion? Doing 14k with the help of relativenumber is great but what about horizontal motions? For large movements, hjkl are actually worse than modifiers+arrows. And guess what? Large movements are what we need the most.

But we are lucky bastards, our favorite editor has dozens of motions that run circles around both the arrows and hjkl: bBeEwW/?*#{}() and so on. These commands are immeasurably more empowering than hjkl and for the most part a lot more logical and intuitive if you are used to Ctrl+Right and friends.

Switching from <Right><Right><Right><Right><Right><Right><Right><Right><Right> to lllllllll or even 9l is ridiculously pointless.

Switching from <Right><Right><Right><Right><Right><Right><Right><Right><Right> to <C-Right> is vastly better. From there, switching to w is both easy and quick. No need to <nop> your arrows!

If these commands are more useful, more powerful and more intuitive than hjkl, why in all hell do so many bloggers and commenters insist on replacing the arrows with hjkl?

I. Have. No. Idea.

In conclusion, hjkl have their place in our toolbelt because we always have to move by 2 characters or lines but they are more often than not the tree that hides the forest. Be wary of people preaching against the arrows: what they have in store for you may not be better at all.