5.3 Jump long distance



The vi command can edit not only a small file but also a big file.

It is difficult to move by a character in a big file. So, you can use commands which move by page, jump to the specific line, and jump to the specific word.


 Command  Action
 [Ctrl] + f  Move to the next screen
 [Ctrl] + b  Move to the previous screen
 :1  Move to the 1st line
 :n  Move to the nth line
 :$  Move to the last line
 [Ctrl] + g  Display information about current position

Table 5-6:Commands for moving by pages and by lines

5.3.1 Page jump

In order to edit large text more quickly, we can use page-jump-commands which let us move to next page or previous page.


Practice: Move page


Open a existed file "/var/log/dmesg" using vi command.
Because it is a log file, you should quit by force without saving, if you change the file.


$ vi /var/log/dmesg ↵
"/var/log/dmesg" [readonly]299L, 14056C


Let's move to the next or previous screen using [Ctrl]+f or [Ctrl]+b.
If you changed the file, quit without saving using ":q!" command.

:q! ?


:q! ↵
$


You can stop inputting command using [Esc] key. If you have mistake to input, input [Esc] key some times, then quit vi command using ":q!" command.

5.3.2 Jump to the specific line

We also can move to specified line directly.

Practice: Move line


Open a existed file "/var/log/dmesg" using vi command.
Because it is a log file, you should quit by force without saving, if you change the file


$ vi /var/log/dmesg ↵
"/var/log/dmesg" [readonly] 299L, 14056C


Let's move to the specific line using ":n" command. You can specify line number after ":" command. If you want to move the 10th line, input ":10".

 

:10 ↵


If you input ":1", you can go back first line.


:1 ↵


If you want to move the last line, input ":$".


:$ ↵
          270,1     Bot


The command for display information about cursor position is [Ctrl]+g.
Input [Ctrl]+g command, then display the current position.
(Display a contents of /var/log/dmesg)
"/var/log/dmesg" [readonly] line 5 of 531 --0%-- col 8


Figure5-6
Figure 5-6: Screen 06-05 Display the number of lines of this moment


If a file is changed, exit without saving using ":q!" command.


:q! ↵
$




Previous Next