Vim Tips
Add Contents in Lines Head
- In normal mode, press
Ctrl-v
into visual-block mode. - Select the lines you want to add contents, press
I
to enter insert mode. - Edit the contents, press
Esc
to exit insert mode, and else lines will be added automatically.
Add Contents in Lines Tail
- In normal mode, press
g
andv
, that will help us to select all contents in the file. - Then press
$
to jump to the end of the line. PressA
to enter insert mode. - Edit the contents, press
Esc
to exit insert mode, and else lines will be added automatically.
Vim Record and Playback
- In normal mode, press
q
anda
to start recording.(a means the name of the recording, you can use any letter) - Then press
i
to enter insert mode, and edit the contents. - Press
Esc
to exit insert mode, and pressq
to stop recording. - In normal mode, press
@
anda
to 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@a
to 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-o
to jump to the previous position. PressCtrl-i
to jump to the next position. Samely, they can jump each other between two files. -
In normal mode, press
gf
to jump to the file which the cursor is pointing to. -
In normal mode, press
gx
to open the url which the cursor is pointing to.