\
To do a good job, he must sharpen his tools
As an essential tool for Linux development, Vi can give full play to the efficacy of the maximum, will certainly improve our work efficiency, the following are some Vi use tips. \
1. Cursor positioning, screen scrolling. \
The command | function |
---|---|
$ | End of current line |
0 | Start of current line |
gg | The file header |
G | end-of-file |
10gg 10G | Skip to line 10 |
` ` | These are the two back quotes, the key below ESC on the keyboard. Return to the position before the cursor jump |
H | Jump to the first line on the screen |
M | Jump to the middle row of the screen |
L | Jump to the last line on the screen |
gk | The previous line seen on the screen |
gj | The next line seen on the screen |
In Vim command mode, there are many commands to move the cursor, which brings us great convenience. The most commonly used is0 和 $, position the cursor at the beginning and end of the line.
Commonly used areGPlace the cursor at the end of the file,ggGo back to the file header. Add a number to the front of both commands to go to that line, for example10ggIt will take you to line 10.
` `Returns to the position before the cursor jump. For example, if the cursor is now at line 10, press G to go to the end of the file and press again to return to line 10.
If you find that sometimesk 和jIt doesn’t work very well (one click spans several lines on the screen), so try it outgk 和gj 。
2. Copy, cut and paste.
The command | function |
---|---|
dd | Delete current row |
yy | Copy the current row |
d$ | Deletes content from cursor position to end of line |
yt< | Copy everything from cursor position up to the next “<” (also,ct<Modify everything from the cursor up to <, which is handy when editing HTML or XML files. |
“X copy | Put the copy into register X (x can be one of the 26 letters, case sensitive) |
“xp | Paste the contents of register X |
“+ | Special register, read and write system clipboard |
:reg | View the contents of each register |
D Deletes the character \ from the cursor to the end of the line