Reputation: 46728
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?
Upvotes: 4
Views: 5515
Reputation:
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
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./ <char> <Enter>
: Go the next occurrence of a character independent of line. After you do this one time, pressing n
or N
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) and N
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 of words
ended by . !
or ?
followed by a space, tab or endline.e
: next word
, place the cursor at the end of the word
w
: next word
, place the cursor at the start of the word
b
: back 1 word
, place the cursor at the start of the word
ge
: back 1 word
, place the cursor at the end of the word
E W B
and gE
: Same as e w b ge
, but with WORD
. 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:
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
Upvotes: 2
Reputation: 6332
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, and dk
deletes the current line and a line above it. The same is of course true for the y
, 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.
Upvotes: 7
Reputation: 6034
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.
Upvotes: 9