Chapter 1: Cursor Movement
Welcome to Chapter 1, this chapter will learn simple cursor movement operations.
If you already have a certain foundation, this part can be skipped, directly G to the end of the document according to the operation into the next chapter.
Before starting, press Esc to make sure you are in Normal mode. Motions are not isolated shortcuts to memorize: later you will combine them with delete, change, and copy operations. For now, focus on describing where to move.
Move the cursor
Unit level
hleft one characterjline downkline uplright one character
Word level
worWmove right to the beginning of the wordeorEmove right to the end of the wordborBmove left to the beginning of the word
Note: Lowercase letters treat word characters as boundaries, uppercase letters treat spaces as boundaries
Try to feel the various movements in the following character blocks!
This project's GitHub url is https://github.com/dofy/learn-vim
Please clone it to your local folder and open the first file which is
named chapter01.md via following command "vim chapter01.md"
and welcome to https://yahaha.net :)Start on
Thisand use only word motions to reachGitHub,https, andlearn-vim. If you overshoot, usebto go back. Notice howwandWbehave differently inside a URL.
Block level
ggto the first line of the documentGto the last line of the document0to the beginning of the line (column 1)^to the first non-whitespace character$to the end of the lineHmove to the top of the screenMmove to the middle of the screenLmove to the bottom of the screenCtrl-dmove down half a pageCtrl-umove up half a pageCtrl-fmove down one pageCtrl-bmove up one page:<N>or<N>ggjump to line N:+<N>or<N>jjump down N lines:-<N>or<N>kjump up N lines
Note: A number N can be added before all commands, which means that the command behind it is executed N times. For example, if you want to move down 3 lines, you can use :+3 or 3j to achieve the same effect. In addition, there are actually two commands above: one is executed immediately after typing, such as gg; the other is to enter : first (there will be a / first), this type of command needs to be executed after the input is completed. Press Enter, which is the same in the following tutorials.
Counts and motions
Most motions accept a count. Instead of pressing j ten times, estimate the distance and use 10j. You do not have to guess perfectly: 8j, followed by a small j or k adjustment, is usually faster.
3wmoves forward three words5jmoves down five lines2Ctrl-dmoves down two half-pages
Use
5jfrom this line and then5kto return. If you miss,uwill not help: it undoes text changes, not cursor movement. Move back in the opposite direction instead.
Now you can swim in the current file. When you are familiar with various movement operations, you can locate the current document to the last line by pressing
Gand enter the next chapter according to the prompt.Place the cursor anywhere in the file name behind it and press the keyboard
gfto enter Chapter 2.