Why use hjkl in vim




















Cursor is placed right before the character; T and F : Backward your character search on this line, however T will put the cursor right after the character or before if you think backwards ; , and F will put it above of it. After you do this one time, pressing n or N goes to the next and previous occurrence.

Paragraphs are basically blocks divided by an empty line. See :help paragraph for further details. A sentence is a group of words ended by. See :help word for further details. Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile.

Linked 2. Related Hot Network Questions. Question feed. Why not something equivalent with right hand, like ijkl or pl;'? Improve this question. Martin Tournoij Check that Wikipedia page of vi , it contains a picture of some ancient Unix machine keyboard which explains, some keybindings.

Because vim is exempt from keeping up with technological advances :3 — Alexander. You can put four fingers of one hand on the hjkl keys, comfortably , and move the cursor all four directions without shifting fingers back and forth. If you really think about it, four in a row is the only cursor key layout consistent with human anatomy. The question is really how everyone else manages to get it wrong.

Actually it's not recommended to put your index on the h but rather on the j that's why you have a "nipple" on the j key. Reason for that is that you will use b much more than h and having ; accessible is handy in a lot of programming language and with a shift, you have : which is ever more handy in Vim.

Show 3 more comments. Active Oldest Votes. Improve this answer. This should still be on every keyboard! Now you've got me wondering what kind of terminal the guy who made emacs had The article explicitly talks about how the design of the keyboard influenced the design of Emacs, and it also compares it to the design of Vi with its ubiquitous Escape key, and the fact that the Escape was very conveniently located on the ADM-3A Terminal's keyboard.

Well, on the Space Cadet Keyboard, there are the Control, Meta, Super, and Hyper keys which are very conveniently located, as well no less than 3 different Shift keys allowing to type over characters. While this answer is correct as such, it sort of moves the question rather than answer it: "Why did the ADM-3A keyboard choose hjkl and not a more logical shape such as ijkl?

Carpetsmoker: we didn't invent keyboard arrow location logic until the late 80s upload. Show 5 more comments. This is why: As you can see, esc is where tab is on most keyboards. Community Bot 1. 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.

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 c i ". 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.

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

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

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? 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? Of course not. 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? And guess what? Large movements are what we need the most. From there, switching to w is both easy and quick.

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? 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. Others have described why other ways of moving the cursor around are preferred, but little has been said to answer the question, why is it considered a bad idea to use arrow keys?

I think the main reason and Squeezy somewhat alluded to this is that back in the days of terminals like the VT, arrow keys produced an escape sequence that was interpreted by the running program. Since arrow keys aren't represented in ASCII, the typing of arrow keys has to be communicated in some "special" way. The escape sequence was typically something like. If your shell or your program weren't configured properly for the terminal, they wouldn't understand the the escape sequence as an arrow key.

When I was in college, logging in to Ultrix via VT terminals, if I pressed an arrow while in vi in insert mode, the ESC would be interpreted as "get out of insert mode", and then the following [ A were interpreted as normal-mode commands. Obviously not what the user wants or expects! Nowadays, the handling of terminals and arrow keys seems to be more robust, especially in GUI environments.

But the same problems do still occur when using vim over SSH or Telnet. Using the arrow keys is frowned upon because it forces you to move your fingers from the homerow when using the QWERTY layout and from the character pad? The arrow keys exhibit a problem - it was already known in vi - on slow connections, like on baud modem. This will not appear with the hjkl keys. To one who is master, and who therefore disdains the arrow keys, the concept of "mode" likewise does not exist.

The master adds new text using not an insert mode, but rather complete insert or replacement commands which begin with an opcode such as i , o or cw that is followed by payload text, and terminated by ESC. Commands have a syntax, and so the machine traverses through states in accepting the syntax of commands, but in the master's model of the editor, these do not give rise to a mode. What the apprentices naively call "mode", is to the master an unfinished command state, a most abhorrent situation which the master avoids.

Whenever the master realizes, whilst in the middle of an insert or replace command, that text must be inserted or deleted other than at the next character position indicated by the cursor, the master terminates the insert command, and unleashes one of the dozens of efficient movement commands resorting to the lowly hjkl if a more powerful way is not obviously applicable.



0コメント

  • 1000 / 1000