Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are h,j,k,l recommended over using arrow keys for vim?

I am a vim user (not a beginner not advanced). I use the arrow keys.
I have repeatedly read that it is highly recommended to use the h,j,k,l keys for increased productivity.
I have tried to use them but I can not see how they help in being more productive.

Because if I am to use the h,j,k,l keys to move up/down/right/left I need to press the ESC first to exit the insert mode.
But that defeats the purpose doesn't it? Since the original idea is that you don't need to move your fingers away.
If I am to press ESC I might as well be using the arrow keys and save a keystroke.
Perhaps I am doing something wrong here?

like image 728
Jim Avatar asked Nov 02 '14 20:11

Jim


3 Answers

Old terminal keyboards like the ADM-3A terminal didn't have arrow keys. The keyboard layout looked like this and it already had the arrows for hjkl. (By the way, also note the relation between ~ and Home key)

ADM-3A terminal

I think it is mainly for historical reasons that vim still uses it (and many are used to it). Perhaps also because many sysadmins are nostalgic about stuff from the 70/80's, and because they can brag about how they can type faster (like typing is the cause of slow coding...).

like image 157
Alex Avatar answered Nov 12 '22 02:11

Alex


The distinguishing feature of vi / Vim is that it's mode-based. That means:

  1. you only stay in insert mode for short bursts of typing
  2. in the other modes (mostly normal mode), you have all key [combinations] available for powerful editing commands (which are highly regular in Vim, and can be combined to great effect)

So, it's crucial that you can switch modes easily. For many users, that means remapping the Esc key to a more convenient location (replacing Caps Lock or Ctrl). Then, using H J K L for navigation (note those are only the basics, and it's often better to use more specific motions like w or f{char}) is quicker, because your fingers can stay on the home row (assuming you're a touch typist, which you should invest in if you spend considerable time with a computer). The cursor keys are located so far off that switching there takes too much time (using the mouse is even worse), and isn't good for your wrists, neither.

like image 24
Ingo Karkat Avatar answered Nov 12 '22 02:11

Ingo Karkat


The problem with the arrows is not that they are too far: the problem is that they only allow you to move character-by-character and line-by-line. And guess what? That is exactly what hjkl do. The only benefit of hjkl over the arrows is that it saves that slight movement of the arm to and from the arrows. Whether you think that benefit is worth the trouble is your call. In my opinion, it isn't.

hjkl are only marginally better than the arrows while Vim's more advanced motions, bBeEwWfFtT,;/?^$ and so on, offer a huge advantage over the arrows and hjkl.

FWIW, I use the arrows for small movements, in normal and insert mode, and the advanced motions above for larger motions.

mouse-using sucker everyone laughs at:  (move)↓↓↓↓↓↓↓↓↓↓→→→→→(move)
hjkl-obsessed hipster:                        jjjjjjjjjjlllll
efficient vimmer:                             /fo<CR>
like image 21
romainl Avatar answered Nov 12 '22 00:11

romainl