Vim Tips
Add Contents in Lines Head
- In normal mode, press
Ctrl-vinto visual-block mode. - Select the lines you want to add contents, press
Ito enter insert mode. - Edit the contents, press
Escto exit insert mode, and else lines will be added automatically.
Add Contents in Lines Tail
- In normal mode, press
gandv, that will help us to select all contents in the file. - Then press
$to jump to the end of the line. PressAto enter insert mode. - Edit the contents, press
Escto exit insert mode, and else lines will be added automatically.
Vim Record and Playback
- In normal mode, press
qandato start recording.(a means the name of the recording, you can use any letter) - Then press
ito enter insert mode, and edit the contents. - Press
Escto exit insert mode, and pressqto stop recording. - In normal mode, press
@andato playback the recording.
Note: When you ending the recording, ensure you cursor is at the head of the next line. Certainly, you can use
10@ato playback the recording 10 times.
Force Save File
Sometimes, you may edit a file in vim, but you don't use sudo. However, you need not to edit it again. You can use fllowing command to save the file:
:w !sudo tee %
Jump Quickly
-
In normal mode, press
Ctrl-oto jump to the previous position. PressCtrl-ito jump to the next position. Samely, they can jump each other between two files. -
In normal mode, press
gfto jump to the file which the cursor is pointing to. -
In normal mode, press
gxto open the url which the cursor is pointing to.