VimTutor says in its first lesson:
NOTE: The cursor keys should also work. But using hjkl you will be able to move around much faster, once you get used to it. Really!
However, I find no difference at all between them. Is there really a difference between using hjkl v/s the arrow keys?
You don't have to move your hand from the touch type position to use hjkl, whereas you do if you use the arrow keys.
In fact, using
h j k l
keys makes a good practice to avoid to much of right hand movimentation on your keyboard when you have to reach the arrow keys but, there are more efficient ways to navigate through a text file using vim:f <char>
: Go to the next occurrence of a character<char>
on the current line. Cursor is placed above the character;t <char>
: Go to the next occurrence of a character<char>
on the current line. Cursor is placed right before the character;T
andF
: Backward your character search on this line, howeverT
will put the cursor right after the character(or before if you think backwards ;) ), andF
will put it above of it./ <char> <Enter>
: Go the next occurrence of a character independent of line. After you do this one time, pressingn
orN
goes to the next and previous occurrence.? <char> <Enter>
: Go to the next occurrence of a character independent of line, backwards.n
will search next occurrence(backwards) andN
will go to the previous.{
and}
: Navigate on paragraphs. Paragraphs are basically blocks divided by an empty line. See:help paragraph
for further details.(
and)
: Navigate back and forward on Sentences(:help sentence
). A sentence is a group ofwords
ended by. !
or?
followed by a space, tab or endline.e
: nextword
, place the cursor at the end of theword
w
: nextword
, place the cursor at the start of theword
b
: back 1word
, place the cursor at the start of theword
ge
: back 1word
, place the cursor at the end of theword
E W B
andgE
: Same ase w b ge
, but withWORD
. See:help word
for further details.If you want to start by getting the first good habits of using
h j k l
or other movements and avoid the arrow keys, pleace the following lines on your .vimrc file inside your home to disable them:The thing is that you start out using the "hjkl" key just as a slightly better way to move your cursor, but the truth is that they are actually
motions
.h
motions one character leftj
motions one line downk
motions one line upl
motions one character rightSo for example, with the delete operator
d
:dl
deletes the current character,dh
deletes the previous character,dj
deletes the current line and a line below it, anddk
deletes the current line and a line above it. The same is of course true for they
,c
,V
,gU
and any operator.Another example are split windows. You can create a couple of windows using Control-w+s and Control-w+v, then use your trusty hjkl to move around between your windows, Control-w+h moves a window left, Control-w+j moves a window down, etcetera.
So it's not just that they are an improvement over the arrow keys. As your understanding of Vim grows, you'll learn that the hjkl keys can be combined with other commands in many ways, and you will be happy you can use them.