Article Directory
Preface
The two major text compilers in the world are vim and emacs, both of which are more powerful text editors.
- vim file
directly edit file content - vim: wq file
file does not exist - vim: wq! file
file exists, the edited content overwrites the original file
1. Three modes of vim
1. Command mode (browsing mode) In
this mode, only the file content can be browsed; the working mode of vim can be set; the file content cannot be modified;
2. Insert mode A mode
to modify the contents of a file
3. Exit the mode and
end the command used by the vim program
How to open the vim manual
- Enter vimtutor
- vim command to open the vim program and input in the program: help
Second, the basic configuration of vim work
How to change the way vim works in command mode?
1. Method: :set setting (temporary setting)
-
: Set nu
display line number -
: Set nonu to
cancel the line number display -
:set mouse=a
mouse is available -
: Set cursorline
displays the line of the line where the cursor is located
2. Method: modify the vim configuration file (permanent setting method)
- vim/etc/vimrc
Three, search
/Keywords-highlight keywords
-
: Noh
cancel highlighting -
n
Downward matching keywords -
N-
up matching keywords
Four, vim character management
y Copy shortcut
- yl
copy a letter - y3l
copy three letters - yw
copy a word - y3w
copy three words - yy
copy a line - y3y
copy three lines (the default is three lines down) - y3<up>
copy three lines (down)
d Shortcut key to delete
-
dl
delete a letter -
d3l
delete three letters -
dw
delete a word -
d3w
delete three words -
dd
delete a line -
d3d
deletes three lines (the default is three lines down) -
d3<up>
delete three lines (up)
c Cut shortcut
- cl
cut 1 letter - c3l
cut 3 letters - cw
cut 1 word - c3w
cut 3 words - cc
cut 1 whole line - c3c
Cut 3 whole lines
Note : Only after the cut operation is completed, it will enter the "insert mode". If you want to paste, you need to press ESC to exit the "insert mode", enter the browse mode and then press P to paste the
P paste shortcut key-command mode under
u recovery shortcut
ctrl + R revocation
Five, vim visualization mode
After entering the visualization mode, press <ESC> to exit the visualization mode.
Add characters in batch: <ctrl >+< v>
- <ctrl >+< v> select the column where the inserted character is located
- Press uppercase <I> to enter insert mode
- Insert the character to be written
- <ESC>Exit insert mode
Batch modify characters
-
:%s/original character/replacement character/g
% full text row, g full text column
-
:1,5s/: /##/g
1,5 In the content of lines 1-5: replace with ##
-
: /Adm/,/sync/s/: /##/g
/adm/,/sync/ In the content between adm character and sync character, replace with ##
Six, vim's split screen function
Sync split screen
- <ctrl> +< w >< s> split screen up and down
- <ctrl> +< w >< v> Left and right split screen
- <ctrl> +< w ><up|down|left|right> cursor movement
- <ctrl> +< w >< c> cancel split screen
Asynchronous split screen
After opening a file with sp file , enter the command and open another (upper and lower split screen)- vim -o file1 file2
split screen up and down, press <crtl+w+down|up> to switch - vim -p file1 file2
left and right split screen, enter tabn/tabp to switch
Seven, quickly locate the cursor in vim
Fast cursor positioning in browse mode
- gg Move the cursor to the beginning of the first line of the file
- G mark moved to the last line
- : Number cursor to the specified line
Eight, vim insert mode entry method
Quick cursor positioning in insert mode
- i Insert at the cursor position
- I Insert at the beginning of the line where the cursor is
- A Insert at the end of the line where the cursor is
- a Insert the next character of the character under the cursor
- o Insert the next line of the line where the cursor is
- O Insert the line above the line where the cursor is
- s delete the character under the cursor
- S Delete the line where the cursor is
Nine, vim exit mode
- :wq save and exit
- wq! Forcibly save and exit (conditions apply: only the file is own or available to the root user)
- :q Exit directly
- :q! Force exit without saving