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

7

12

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?

Mullock answered 2/11, 2014 at 20:5 Comment(8)
This isn't really a programming question.Dale
@Soren:What is the tag vim then supposed to be?Mullock
There are people who can hit [Esc] instantly with their left pinky finger, so I guess that does not make a difference to them. On the other hand, I've been productive using the arrow keys under Vim for ages, no lightning bolt has struck me yet, and I can still use my left pinky finger.Temperance
@Jim, No, it is about how to program vim.Dale
@Soren, questions about tools made for programming (as Vim is) are on-topic on Stack Overflow. If anything, this question is primarily opinion-based, not off-topic.Temperance
@FredericHamidi:That is good to know because every blog I read mentions this. I was wondering if I am doing it wrongMullock
"I need to press the ESC first to exit the insert mode." You could use CTRL-[ with your two pinkies, and not leave the home row.Tosh
Historically, vi (not vim) didn't support the use of arrow keys in insert mode (and because of that I've never picked up the habit of using that way). The advice might have been written from that perspective. For a touch typist, it's very nice not to have to move your hand off the home row (to arrow keys that can be in different places on different keyboards, though that's probably not as much of an issue these days as it used to be).Steeple
I
10

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...).

Ireful answered 24/3, 2015 at 21:18 Comment(0)
D
5

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.

Duckpin answered 2/11, 2014 at 20:21 Comment(2)
1) I am not sure what you mean by "short bursts of typing". I use vim as a coding editor so I type a lot. 2) Remap Caps Lock or Ctrl? And how would I use the CTRL key then which i use a lot or the Caps if I need it?Mullock
1) Inserting characters is only a fraction, especially when coding. 2) You can swap the keys, so you don't lose any. Some tools even allow a nifty double use: Ctrl in combination with another key, Esc when pressed alone.Duckpin
G
2

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>
Goulet answered 2/11, 2014 at 20:47 Comment(0)
T
1

h, j, k, and l are on the home row. If you move your hand to use the arrow keys, you have to readjust when you're done with the arrow keys. This is only a problem for touch typists (which everyone back in the day was).

Tisatisane answered 28/2, 2018 at 14:25 Comment(0)
O
0

If you like using the arrow keys, by all means, use them. There is one advantage I see over hjkl: arrow keys work in insert mode. Others prefer to move their fingers only minimally. That's a good argument if you are a touch typist and need to type lots of text. At least for me, my thinking is always slower than my editing, so typing speed and minimal finger movement are not so much an issue to me.

In the end, it's a pretty subjective matter. Use what works for you but try to look around and extend your horizon now and then.

Overstrung answered 2/11, 2014 at 20:28 Comment(1)
Since it's a subjective matter, I'll be the devil's advocate here :) Don't get too used to arrow keys working in insert mode -- for instance, I recently helped with installing a Xubuntu distribution, and the default package for Vim there (vim-tiny IIRC) clutters your file with escape sequences if you try that.Temperance
D
0

h j k l are a stepping stone to more powerful features. Do you really think that left, right, up, down is as advanced as moving the cursor gets in the 21st Century (or 1976)?

Deceitful answered 3/11, 2014 at 2:11 Comment(0)
C
0

Please note that arrow keys are not recorded while using "q" macros, and bring a lot of sheanigans when you are using some esoteric options because arrows interrupt them. The idea with vim is to end up using composable actions as often as possible and arrows are not.

Besides it doesn't make much of a difference anyway. I had the same strule as a kid switching arrows for WASD, once you get used to it it's just another way, closer to where your hand already is.

And it's not just vim, you would not believe how convenient it is to go the extra mile and learn the terminal shortcuts for movement, copy-paste, history, etc. My laptop's arrows broke last year and I couldn't find the time to solve the issue (Amazon reach the space, but not the island where I live). It was a blessing. Now I rarely use arrows anymore, because ctrl-p/ctrl-n/ctrl-b/ctrl-f/etc. it's just more ergonomic. I just lay my hands on top of the keyboard and don't move them anymore. Ironically now the fartest I move my hands from standard position is to press ESC, wich happens quite often in vim.

A few times I've heard "wait, your terminal/editor can do what!?" when doing fancy things with public. Probably their toolset can do it too, but they haven't go the extra mile of truly learning them. Trust me, it's worthwhile to do so. These tools have been designed this way for a reason.

Crossstaff answered 2/2, 2022 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.