These are just a few of the movements that vim is capable of, these should get you going for now.
TL;DR
- Use Vim's built in help feature on
navigation
or better still usr_03.txt
- Search google for
vim advanced movements
- Navigate with/to words
- go here All the right moves
Movements
There are many ways of getting around in vim I have listed some that I found by searching for vim advanced movements
, and a few that I use all the time. Im sure you know of most of these but the ones I think you will want to pay particular attention too are the word navigation's.
Here are a few that allow for navigation inside a line.
0
– go to the starting of the current line.
^
– go to the first non blank character of the line.
$
– go to the end of the current line.
g_
– go to the last non blank character of the line.
Navigation with words can be very helpful. To be more granular, you should navigate in relation to words, using:
e
– go to the end of the current word.
E
– go to the end of the current WORD.
b
– go to the previous (before) word.
B
– go to the previous (before) WORD.
w
– go to the next word.
W
– go to the next WORD.
A word consists of a sequence of letters, digits and underscores.
A WORD consists of a sequence of non-blank characters, separated with white space.
words|WORDS may also change depending on your vim settings.
Example to show the difference between WORD and word
192.168.1.1
is single WORD.
192.168.1.1
is seven words.
The search movements can be extremely useful too.
/pattern
– Search for a pattern which will you take you to the next occurrence of pattern
n
will take you to the next match of pattern
below the cursor.
?pattern
– Search for a pattern which will you take you to the previous occurrence of pattern
.
N
will take you to the next match of pattern
above the the cursor.
*
– Go to the next occurrence of the current word under the cursor.
#
– Go to the previous occurrence of the current word under the cursor.
%
– Go to the matching braces, or parenthesis inside code.
Here are a few you can do even before you open vim, from the command line
Vim +N filename
allows you to go to the Nth line of the file after opening it.
vim +10 /etc/passwd
Vim +/pattern filename
opens the file to the first line with the occurrence of the pattern
. In the following example, vim will open the README file and jump to the first occurrence of the word “install”.
vim +/install README
Vim +?patten filename
opens the file to the last occurrence of pattern
. In the following example, it will open the README file and jump to the last occurrence of the word “bug”.
vim +?bug README
/
and?
.hjkl
is a good thing. What I was disapproving was the plugin itself: In my opinion it is better to learn new ways to navigate once at the time (you can't learn all of them at the same time) and during the learning using plugins which frustrates you is not necessary. That being said it is only my opinion: one has right to disagree :-)That being said it is only my opinion: one has right to disagree
. Now, the debate is potentially endless: of course some people will benefit of this kind of plugin whereas it will only frustrate some other and harm their learning. If you'd like to talk about it I'll gladly discuss with you in a chat but we shouldn't spam the comments of the question with this kind of debate :-)