Vim-vi Improved:
Vim is the VI editor of the upgrade version, is the standard Linux editor, with program writing ability, according to the font color to distinguish the correctness of the grammar, convenient program design.
Use:
# vim [OPTION] ... FILE ...
+#: After opening the file, just leave the cursor at the beginning of line #
+/pattern: Immediately after opening the file, leave the cursor at the beginning of the first line that is matched to the PATTERN
Basic mode:
Edit mode (Command mode): Open the default mode of the file, you can move the cursor up or down, copy and paste delete data
Input mode: Press I,i,o,o,a,a to enter in edit mode, press ESC to exit
Last-line mode: Built-in command-line interface, press ":,/,?" in edit mode 3 any one into
Mode conversion:
Edit mode--Input mode
I:insert, start typing at the cursor position;
A:append, start typing at the next character where the cursor is located;
o: Insert a new line below the line where the cursor is located;
I: Start typing at the first non-whitespace character of the line where the cursor is located;
A: Start typing at the last character of the line where the cursor is located;
O: Insert a new line above the line where the cursor is located;
Input mode--edit mode
Esc
Edit Mode--last-line mode
:,/,?
Last-line mode--edit mode
Esc
Vim Save or Exit command:
: W Save
: w! Force Save
: Q exit
: q! You do not want to save after modifying a file, forcing quit does not save
: Wq Save Exit
: wq! Force Save exit
ZZ If the file is not changed, do not save the exit, if the file has changed, then save the exit
Edit mode:
Cursor Jump:
Jump between characters:
H or ←: The cursor moves one character to the left
J or ↓: Move the cursor down one character
K or ↑: Cursor moves up one character
L or →: The cursor moves one character to the right
#COMMAND: Jump # Number of characters
Jump between words:
W: The first word of the next word
E: The ending of the current or next word
B: The first word of the current or previous word
#COMMAND: Jump # Number of words
Beginning line End Jump:
^: jumps to the first non-whitespace character at the beginning of a line
0: Jump to the beginning of the line
$: Jump to end of line
Move between rows:
#G: Jump to # line
G: Last line
1G or GG: First line
Edit command:
X: Remove one character backwards
X: Delete one character forward
#x或 #x: Remove the # characters backwards or forwards, such as 10 characters backwards, "10x"
R: Replace the character at the cursor at the same time
R: Always replace the character at the cursor until ESC is pressed
D: Delete command, can be combined with the cursor jump character, to achieve range deletion:
such as: "d$" delete the cursor at the end of the line, "d^" delete the cursor at the beginning of the first non-whitespace characters and so on.
DD: Delete the line where the cursor is located
#dd: Delete the line where the cursor is down # line
P: If the buffer exists as a whole line, paste it below the current cursor, or paste it at the end of the current cursor.
P: If the buffer is full line, paste it above the current cursor, or paste it at the front of the current cursor.
Y: Copy command, works similarly with d command
such as: "y$" copy cursor at the end of the line, "y^" copy the cursor at the beginning of the first non-whitespace characters and so on.
YY: Copy the line where the current cursor is located
#yy: Copy the line where the current cursor is located down # line
C: Delete and enter the input mode from edit mode, using the same method as the D command, here is not much to say
Other editing operations:
Visualization mode:
V: Selected by character
V: Selected by row
Note: frequently combined editing commands D,c,y
To undo previous edits:
U: Undo Previous Action
#u: Undo the operation of # times
To revoke a previous revocation:
Ctrl+r
Repeat the previous edit operation:
.
Turn screen operation:
CTRL+F: Flip a screen to the end of the file
CTRL+B: Flip a screen to the file header
Ctrl+d: Turn half screen at the end of the file
Ctrl+u: Turn half screen to file header
Last-line mode:
Built-in command-line interface
(1) Address delimitation
#: The specific # line, for example, 2 means line 2nd;
#,#: From the left # indicates the line start, to the right # indicates the end of the line;
#,+#: The line starting from the left # representation, the number of rows represented by the current cursor line plus the right #;
.: When moving forward
$: Last line
., $-1: Current line to bottom 2nd line
%: Full text, equivalent to 1,$
/pattern1/,/pattern2/: Starting from the first line that is matched to the PATTERN1 pattern, until the end of the line that was first matched to the PATTERN2
#,/pattern/: # line to the first line to be matched to by pattern pattern
/pattern/,$: The first line to be matched by the pattern pattern to the last row
How to use:
followed by an edit command:
D: Delete
Y: Copy
w [filename]: Save a range of rows to a specified file
R [FileName]: Inserts the specified file at the specified location so the content
(2) Find
/pattern: Looks at the end of the file from the current cursor location;
? PATTERN: From the current cursor location to the file header lookup;
N: Find the next with the command in the same direction;
N: Find previous with command reverse direction;
(3) Find and replace
S: Complete the Find and replace operation in the last line mode
s/what to look for/replace with content/modifiers
What to look for: Available modes
Replace with: cannot use mode, but can use \1, \2, ... You can also use "&" to refer to the entire content found in the previous lookup;
Modifier:
I: Ignore case
G: global substitution; By default, each row replaces only the first occurrence;
Find separators in substitutions/can be replaced with other characters, such as
[Email protected]@@
s###
Customizing the working characteristics of vim:
Configuration file: Permanently valid
Global:/ETC/VIMRC
Personal: ~/.VIMRC
Last line: The current VIM process is valid
(1) Line number
Display: Set number, abbreviated as set Nu
Cancel display: Set Nonumber, abbreviated to set Nonu
(2) Bracket matching
Match: Set Showmatch, abbreviated as set SM
Cancel: Set NOSM
(3) Auto Indent
Enable: Set AI
Disabled: Set Noai
(4) Highlight Search
Enabled: Set Hlsearch
Disabled: Set Nohlsearch
(5) syntax highlighting
Enabled: Syntax on
Disabled: Syntax off
(6) Case of ignoring characters
Enable: Set IC
Do not ignore: set Noic
Vim comes with a practice tutorial:
# Vimtutor
Using the VIM editor under Linux