Linux Text Editor-VIM basic usage, linux Text Editor-vim
Vim [OPTION]... FILE...
+/PATTERN: After opening the file, directly place the cursor at the beginning of the first line matched by PATTERN
Vim + file open file directly, and the cursor is in the last line
Three main modes:
Command mode: move the cursor, cut and paste
Insert mode: Edit and modify text
Extended Mode: Save and exit
Mode Conversion:
A insert content behind the cursor
A inserts content at the end of the row where the cursor is located
I insert content from front of the current cursor
I insert content at the beginning of the row where the cursor is located
O insert blank rows under the current cursor
O insert blank lines to the current cursor
Insert mode --> command mode esc
Command mode --> extended mode :,? ,/
Extended Mode --> command mode esc
Enable and exit vim:
If the vim file exists, open the file. If the file does not exist, create a new file.
Command mode cursor jump:
Jump between words:
H: left, l: Right, j: bottom, and k: Top (the upper and lower left keys are supported)
Jump between words:
W: the beginning of the next word
E: the end of the current or next word.
B: the beginning of the current or previous word
Intra-row jump:
Home ^ jump the cursor to the beginning of the line
End $ jump the cursor to the End of the row
0 jump to the beginning of the absolute line
Inter-line jump: (# represents any number)
1G = gg jump to the first line of the file
G jump to the end of the file
# G jump to the file # Line (command mode)
: # Jump to the file # Line (last line mode)
Sentence movement:
): Next sentence (: previous sentence
Move between paragraphs:
}: Next section {: Previous section
Current page Jump:
H: Top, M: middle, L: low
Page flip:
PgDn Ctrl + f flip down one page
PgUp Ctrl + B flip up one page
Basic operations in the extended mode:
: Q exit
: Q! Force exit
: W save
: Wq save and exit = ZZ =: x
: X Encryption
: Wq! Force save and exit
:! Command to execute External commands in vim
: E file: edit file
: W file: Save the current file as file
: R file: reads the content of a file.
$1 $ yyzOv8eO $ a0q8buf801_jty8hx0hy/: r! Openssl passwd-1 # extended mode: use external commands to generate encrypted strings and read them into files
Command mode character Editing:
X deletes the character at the cursor;
# X Delete the starting # characters at the cursor position
The character at the place where the xp switching cursor is located and its position after the character
~ Case sensitivity
R replaces the character at the cursor
R enters replacement Mode
D. The DELETE command can be used in conjunction with the cursor jump character to delete the range;
D $ Delete to the end of the row
D ^ Delete to the beginning of a non-empty row
D0 Delete to the beginning of a row
Dd deletes the row where the cursor is located.
# Delete dd # Row
Delete dG to the end row
Delete dgg to the first line
Yy copies the row where the current cursor is located (y $, y0, y ^, etc. are supported)
# Yy copy the current cursor down # Line
P Paste
C modification, (y $, y0, y ^, etc. are supported)
J. merge the current row and the next row
U cancels the last operation and can be used multiple times
U cancels all operations on the current row
Ctrl + r restore the Undo operation using the u command
. Repeat the previous operation
N. Repeat the previous operation n times.
Extension mode address demarcation:
: 2, + 3 indicates 2 to 5 rows
:. Vertex indicates the current row
: $ Indicates the last row.
: % Indicates the full text, equivalent to 1, $
/P1,/p2: the first row that is matched by p1 to the row that is matched by p2 for the first time
Extended Mode string SEARCH:
/World search for world from top to bottom
? World search from bottom up
N locate the next matched string
N locate the previous matched string
Extension mode string replacement:
: S/old/new: Replace the first character "old" string found in the current row with "new"
: S/old/new/g replace all the strings "old" found in the current row with "new"
: #,# S/old/new/g replace all strings "old" with "new" in the range"
: % S/old/new/g replace all strings "old" with "new" throughout the file"
: S/old/new/c add the c command at the end of the replacement command. Each replacement action prompts the user to confirm.
: % S/^ \ s * // g Delete the first space in the row
: G/^ $/d Delete empty rows
: 5, 10 s/^/#/g insert # comments at the beginning of the line 5 to 10
Visual mode:
The text block that can be selected instead of the mouse. Highlighted text can be deleted, copied, changed, filtered, searched/replaced, etc.
V character-oriented
V line-oriented
Ctrl-v block orientation
Multi-file mode:
Vim file1 file2 file3...
: Next
: Prev previous
: First
: Last
: Wall save all
: Qall: Exit all
: Wqall
Multi-file window:
Vim-o file1 file2...
-O horizontal segmentation
-O vertical segmentation
Switch between windows: ctrl + w
Single file window:
Ctrl + w, s: split, horizontal split
Ctrl + w, v: vertical, vertical Split
Ctrl + w, q: cancel the adjacent window
Ctrl + w, o: cancel all windows
: Wqall exit
Custom vim features:
Configuration file:
Global:/etc/vimrc
Individuals :~ /. Vimrc
1. row number:
Permanent modification:
In the/root/. vimrc file, add
Set nu
: Set nonu remove row number
Temporary row number: (Extended Mode)
: Set nu display row number
: Set nonu does not display row numbers
2. Matching in parentheses:
Matching: set sm
Cancel: set nosm
3. Automatic indent:
Enable: set ai
Disabled: set noai
4. Highlighted search:
Enable: set hlsearch
Disabled: set nohlsearch
5. syntax highlighting:
Enable: syntax on
Disable: syntax off
6. Ignore the case sensitivity of Characters
Enable: set ic
Ignore: set noic
7. File Format:
Enabled: fileformat = unix
Ignore: fileformat = dos
8. set text width
: Set textwidth = 65 (vim only)
: Set wrapmargin = 15
Vim registers:
There are 26 naming registers and 1 non-naming register, which often store different clipboard content and can be shared between different sessions.
There are 10 digit registers, using 0, 1 ,..., 9 indicates that 0 stores the last copied content, and 1 stores the last deleted content. When a new text is changed or deleted, 1 to 2 to 3, and so on. Digital registers cannot be shared between different sessions.