Linux vim editor and linuxvim
Common vim operations self-Summary, please avoid:
Vim open and exit save
Open:
Open vim practice_1.txt directly
You can also open vim first, and then: e file path
Save:
: W file name
Or exit and save: wq!
Exit vim: Shift + zz in Normal Mode
Vim move and enter insert mode
Mobile:
W next word
B. Previous word
Enter insert mode
Command description
I edit at the current cursor
I insert at the beginning of a row
A Insert at the end of A row
A insert and edit behind the cursor
O Insert a new row after the current row
O Insert a new row before the current row
Cw replaces the character from the cursor position to the end of a word
Vim selection mode
V (lower case) to enter the character selection mode
Shift + v (lower case) to enter the row selection mode
Ctrl + v (lower case). This is the area selection mode. You can select the rectangular area,
In visual mode, enter d to delete the content of the selected region.
In visual mode, enter y to copy the content of the selected region.
Vim inter-line jump and intra-line jump
NG jumps to row n
Gg first line
G last line
Ctrol + o jump to the position of the previous jump, which can be repeated similar to history
Command description
W to the beginning of the next word
E to the end of the next word
B to the beginning of the previous word
Ge to the end of the previous word
0 or ^ to the row Header
$ To the end of a row
F <letter> Search backward <letter> and jump to the first matched position (very practical)
F <letter> search forward <letter> and jump to the first matched position
T <letter> Search backward <letter> and jump to a letter before the first matching position (not commonly used)
T <letter> search forward <letter> and jump to a letter after the first matching position (not commonly used)
Vim copy and paste
Y Replication
In normal mode, yy copies the entire row of the cursor (3yy indicates copying 3 rows)
In normal mode, copy y ^ to the first line or y0. It does not contain characters at the cursor position.
In normal mode, copy y $ to the end of the row. Contains characters at the cursor position.
In normal mode, yw copies a word.
In normal mode, two words are copied by the y2w command.
In normal mode, copy yG to the end of the text.
In normal mode, copy y1G to the beginning of the text.
P Paste
In normal mode, p (lower case) indicates that the cursor is pasted (lower case)
In normal mode, P (uppercase) indicates that it is pasted before the cursor (top)
D cut
Vim Delete shortcuts
Command description
X Delete the character of the cursor
X Delete the first character of the cursor
Delete is the same as x
Dd deletes the entire row
Dw deletes a word (not applicable to Chinese)
D $ or D to the end of the row
D ^ Delete to the beginning of the row
Delete dG to the end of the document
Delete d1G to Document Header
Add a number before the command to indicate repeated operations.
2dd
Vim multi-file editing
Vim 1.txt 2.txt
Open a new file after entering vim
In command line mode, enter e 3.txt to open the new file 3.txt.
In command line mode, enter: e # to return to the previous file.
In command line mode, enter ls to list previously edited documents.
In command line mode, enter B 2.txt( ))2.to directly import the file 2.txt for editing.
In command line mode, enter bd 2.txt( or number) to delete the file items in the previously edited list.
In command line mode, enter: e! 4.txt: open the file 4.txt and discard the file being edited.
In command line mode, enter: f to display the file name being edited.
In command line mode, enter f new.txt to change the file name to new.txt.
If the document is not saved due to power failure or other reasons, use the restoration method. After vim-r enters the document, enter ewcover 1.txt to restore the file.
$ Vim-r 1.txt
Vim display row number
: Set nu
Vim replacement
R + <letters to be replaced> Replace the cursor with the specified letter
R is replaced consecutively until you Press Esc.
Cc replaces the entire row, that is, the row where the cursor is located is deleted and enters the insert mode.
Cw replaces a word, that is, deleting a word and entering the insertion mode.
C (uppercase) after the cursor is replaced by the end of the row
~ Returns the case sensitivity of the cursor.
U {n} undo one or n operations
U (uppercase) undo all changes to the current row
Ctrl + r redo: undo
Vim search
/Icmp search for icmp
? Tcp forward lookup tcp
N next
N move to the previous one
Vim repeated commands
.
You can also enter a number before the command
Run External commands in vim.
Enter!
:! Ls is used to display the content of the current directory
:! Rm FILENAME is used to delete a file named FILENAME.
: W FILENAME: Save the file being edited in VIM as a FILENAME file.
Vim text alignment
: Ce
: Ri
: Le
Vim document encryption
Vim-x file1
Vim indent
>
<
View settings:
Set shiftwidth?
Set Value:
Set shiftwidth = 10
Vim settings
2.7.1 vim function settings
Vim configuration file ~ /. Vimrc (the configuration file in the experiment building environment is in/etc/vim/vimrc). You can open the file and modify it, but be careful not to affect normal use of vim.
2.7.2 get current settings
In command line mode, enter: set or: se to display all modified configurations.
In command line mode, enter: set all to display all set values.
In command line mode, enter: set option? Displays the set value of option.
In command line mode, enter: set nooption to cancel the current setting value.
2.7.3 description of the set Function
In command line mode, enter: set autoindent (ai) to set Automatic indent.
In command line mode, enter: set autowrite (aw) to set automatic archiving, which is not enabled by default.
In command line mode, enter set background = dark or light to set the background style.
In command line mode, enter: set backup (bk) to set automatic backup, which is not enabled by default.
In command line mode, enter: set cindent (cin) to set C language indent.