(1) Address delimitation
: Start_pos[,end_pos]
#: A specific line of #, for example, 5 is the 5th line;
.: Current line;
$: last line;
#,#: Specifies the row range, the left is the starting line, the right side is the end line;
#,+#: Specifies the line range, the left side is the absolute number of the first row, and the right side is the offset from the left row number; For example: 3,+7
., $-1
1,$
%: Full text
/pattern/: The line from the beginning of the cursor to the first time the end of the file is matched by the pattern;
/first/,$
/PAT1/,/PAT2/: Starting at the beginning of the cursor, the first line that is matched by PAT1 to all rows between the end of the line that was first matched by PAT2;
Can be used together with editing commands for editing operations:
D
Y
C
W/path/to/somefile: Saves the text in the range to the specified file;
R/path/from/somefile: Reads and inserts the text from the specified file into the specified position;
(2) Find
/pattern: Finds all strings that can be matched to the current pattern from the current cursor location to the end of the file;
? Pattern: finds all strings that can be matched to the current pattern from the current cursor position to the file header;
N: Next, same as command direction;
N: Previous, opposite of command direction;
(3) Find and replace
S: Commands in the last-line mode, using format:
s/what to look for/replace with content/modifiers
What to look for: You can use regular expressions;
Replace with: cannot use the next expression, but can be referenced;
If the "What to find" section uses a grouping symbol in a pattern: use a back reference in "Replace with";
Direct reference to find the pattern to match all the text, to use the & symbol;
Modifier:
I: ignoring case;
G: Global substitution means that if a row is matched to multiple times, it is replaced;
You can replace the delimiter with other non-characters commonly used characters:
[Email protected]@@
s###
Example:
%[email protected]\<t\ ([[: Alpha:]]\+\) \>@t\[email protected]
%[email Protected]\<t[[:alpha:]]\+\>@&[email protected]
Vim's multi-file feature:
Multiple files:
Vim FILE1 FILE2 ...
To switch between files:
: Next Next
:p Rev Previous
: First One
: Last One
Exit All Files:
: Wqall Save all files and exit;
: Wall
: Qall
Multiple windows:
-O: Horizontal split window
-O: Vertical Split window
Switch between windows: Ctrl+w, ARROW
Note: A single file can also be split into multiple windows for viewing:
Ctrl+w, S: Horizontal split window
Ctrl+w, V: Vertical Split window
Customizing the working characteristics of vim:
Note: The settings in the last line mode are only valid for the current VIM process;
Permanently valid:
Global:/ETC/VIMRC
User personal: ~/.VIMRC
1, line number
Display: Set number, abbreviated as set Nu
Cancel display: Set Nomber, set Nonu
2. Bracket matching highlighting
Match: Set Showmatch, 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. Ignore character case
Enable: Set IC
Disabled: Set Noic
Get help:
: Help
: Help Subject
Vim end-of-line mode