Vim Editor
Vim is a very useful text editor for Linux
There are three basic modes of VIM: Edit mode, command mode and last line mode
The following sections describe the operation of each of the three modes
First, we introduce the conversion methods of three modes:
Edit mode--Input mode
I:insert, enter at the cursor position;
A:append, enter at the back of the cursor position;
O: Opens a new line below the line where the cursor is currently located;
I: Enter at the beginning of the line where the cursor is currently located;
A: Enter at the end of the line at the current cursor;
O: Opens a new line above the line where the cursor is currently located;
C
C
Input mode--edit mode
Esc
Edit Mode--last-line mode
:
Last-line mode--edit mode
Esc
What you can do in edit mode:
Cursor Jump:
Jump between characters:
H: Jumps one character to the left
L: Jump one character to the right
J: Jump down one character
K: Jumps up one character
#COMMAND: Jump # Characters by COMMAND
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 according to COMMAND
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: Jumps to the line specified by #;
G: last line;
1G, GG: First line;
Move between sentences:
)
(
Move between paragraphs:
}
{
Character editing:
X: Delete the character at the cursor;
#x: Delete the # characters at the beginning of the cursor;
XP: Swap the position of the character where the cursor is located and the character behind it;
Replace command (R, replace)
R: the character at which the cursor is replaced
Delete command:
D: Delete command, can be combined with the cursor jump character, to achieve range deletion;
d$: Delete the contents of the cursor at the end of the line
d^: Delete the contents of the cursor at the beginning of the line
D0: Delete the contents of the cursor at the beginning of the line
DW: Delete the first word at the cursor to the next word
De: Delete the ending of the current word at the cursor
DB: Delete the first word at the cursor to the current word
DD: Delete the line where the cursor is located;
#dd: Multi-line deletion;
Paste command (p, put, paste):
P: If the buffer is an entire row, the current cursor is pasted below the line, otherwise, it will be pasted at the back of the current cursor;
P: If the buffer is an entire row, the current cursor is pasted above the row, otherwise, it is pasted at the front of the current cursor;
Copy command (y, yank):
Y: Copy, work behaves similar to D command;
y$: Copy the contents of the cursor at the end of the line
Y0: Copy the contents of the cursor at the beginning of the line
y^: Copy the contents of the cursor at the beginning of the line
Ye: Copying the content at the cursor to the ending
YW: Copy the contents of the cursor at the beginning of the next word
YB: Copying the contents of the cursor to the beginning of the word
YY: Copying rows
#yy: Copying Multiple lines
changing commands (c, change)
C: Modify
Edit mode--Input mode
C $: Modify the contents of the cursor at the end of the line
c^: Modify the contents of the cursor at the beginning of the line
C0: Modify the contents of the cursor at the beginning of the line
CB: Modify the contents of the cursor to the beginning of the word
Ce: Modifies the content at the cursor to the ending
CW: Modifies the contents of the cursor at the beginning of the word
CC: Delete and enter new content
#cc: Modifying the contents of a # specified row
Visualization mode:
V: Selected by character
V: set by row
What you can do in the last line mode
(1) Address delimitation
: Start_pos,end_pos
#: 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 start of the line from the left #, plus the number of rows on the right #;
.: When moving forward
$: Last line
%: Full text, equivalent to 1,$
/pat1/,/pat2/:
Starting from the first line that is matched to the pat1 pattern, until the end of the line to which the first match is PAT2;
How to use:
followed by an edit command
D
Y
W/path/to/somewhere: Save the range of rows to the specified file;
R/path/from/somefile: Inserts all the contents of the specified file at the specified location;
(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: In the same direction as the command;
N: Opposite direction with command;
(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###
In addition vim supports multi-file mode:
Vim FILE FILE2 FILE3 ...
In the last line mode, enter:
: Next Next file
:p Rev A previous file
: First File
: Last File
: Wall Save All files
: Qall Exit All Files
Window-delimited mode:
Vim-o|-o FILE1 FILE2 ...
-O: Horizontal split
-O: Vertical split
Switching between windows: Ctrl+w
Single File Window segmentation:
Ctrl+w,s:split, Horizontal split
Ctrl+w,v:vertical, Vertical split
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
Linux Learning notes--vim operation use