Want to see the full-length video right now for free?Sign In with GitHub for Free Access
Motions are used to get your cursor where you want it.
As programmers, we tend to spend most of our time editing existing code. This means we spend a lot of time navigating files and positioning the cursor where we want it, and not much time simply typing new code. Fortunately, Vim is optimized for this situation and has many ways to efficiently move your cursor where you want it.
||move left/right by character|
||move forward one (w)ord|
||move (b)ackward one word|
||move forward to the (e)nd a word|
Many of the motions in Vim have inverses that allow you to go back if you go
too far, e.g.
b. This means that you don't have to be perfectly
precise in your motions, but can simply hit
w a few times, realize you've
gone one too far, and use
b to go back.
Note If you find yourself repeating or holding down a motion key to move around, take a second to consider if there is a more efficient motion.
While the motion commands above are very useful, there are a handful of more precise motions that you can use to more directly jump within a line in a single motion.
||(f)ind a character forward in a line and move to it|
||find a character forward in a line and move un(t)il it (one character before)|
||(f)ind a character backward in a line and move to it|
||find a character backward in a line and move un(t)il it|
T are more powerful than
b as they allow
you to jump to a specific character, regardless of how far that character is
from the cursor.
f "Finds" the character, leaving your cursor on it
t goes "un*T*il" the character, leaving your cursor just before it.
Similarly, while both both
t target to the right of the cursor,
T will target before the cursor.
T by repeating or
reversing the last
T allowing you to hone in on your
target character and freeing you from the need to be perfectly precise in
Now that we have an understanding of how to move within a line, let's tackle moving between lines.
||move up/down one line|
||move (H)igh, (M)iddle, or (L)ow within the viewport|
||repeat last search|
||repeat last search in opposite direction|
||move (u)p or (d)own|
||(G)o to line number NN (useful if you have a failing test on a given line)|
As with the previous sections we can see that there is a similar pattern to
motions and their inverses.
n moves forward through search results,
C-u moves up half a page,
Remember, don't worry about learning all of the motions and commands at once, but instead try to regularly bring one or two new commands, motions, etc into your muscle memory.