Linux vim editor Usage Details, linuxvim Usage Details
In Linux, the main editor is vi or vim. This article describes how to use vim:
The vi (vim) editor is provided in Linux by default, and its package is:
[Root @ xuegod163 ~] # Rpm-qf 'which vi'
Vim-minimal-7.2.411-1.8.el6.x86_64
[Root @ xuegod163 ~] # Rpm-qf 'which vim'
Vim-enhanced-7.2.411-1.8.el6.x86_64
Switch the vim editor mode:
Command mode, command line mode, edit mode
Command mode:
Character operations
I insert before the current character
Insert at the beginning of line I
Insert a after the current character
Insert at the end of Row
Esc exit Current Mode
O Insert the next row
O Insert the last row
X deletes a character backward (equivalent to the delete key)
X deletes one character forward (equivalent to the Backspace key)
U undo step
Row operation
Home key or ^ line beginning
$ End key at the end of a row
Ndd deletes N rows (N indicates the number of rows, 1 can be ignored)
Nyy copies N rows (N indicates the number of rows, 1 can be ignored)
P copy and paste the row
Extension: Cut = Delete first, then Paste
Delete to the beginning of the row d + HOME or ^
Delete to the END of a row d + END or $
Word operations
Dw deletes a word. When deleting a word, you need to move the cursor to the beginning of the line of the word. In addition, if the cursor is not at the beginning of the line, the letter after the cursor is deleted.
Copy a word from yw
W switch words
Block operation
D or d + $ Delete to the end of a row d + ^ Delete to the beginning of a row
Y + $ copy to end y + ^ copy to first
V mode (mostly used for shell multi-line comments and may be used in configuration files)
Enter the v mode: CTRL + V
Multi-line comments are required during programming:
1. Note: press ctrl + v to enter the column editing mode.
2 move the cursor down or up
3. mark the beginning of the line to be commented out
4. Then, press the uppercase I
5. Insert the annotator, for example "#".
6. Press Esc, and all comments will be made.
Delete comments from multiple rows:
Delete: press ctrl + v to enter the column editing mode. move the cursor down or up. Select the comments section and press d to delete the comments.
VIM command line mode operation
: W save
: Q has not been modified. quit.
: Q! Modified, not saved, forced exit
: Wq save and exit
: Wq! Force save and exit.
Save:
ZZ
Change one character: r corresponds to the text
Replace
: % S/this/that the first this in each row is replaced with that
: % S/this/that/g replace all this in the text with that
% Indicates full-text match
S replacement
This original content
That indicates the modified content.
All matching items in a row of g. None replaces the first matching item.
: S/nologin/login/g # Replace nologin from the second row to the fifth row
N, m indicates the specified row number.
/Search:/target n searches down, N searches up
: Set nu/nonu # display the row number
Remove highlight: noh or search for a group of characters that do not exist
:! Ifconfig calls system commands
Locate a line in vim:
Locate gg to the beginning of the line
G. Locate the last line.
# G locate a row
: # Locate a row
# Locate a line by gg
# Representing the row number
Read Other files
: R./sshd_config.bak
Vim open multiple files:
[Root @ xuegod163 ~] # Vim-O/etc/passwd/etc/hosts
Ctrl + WW switch between files
Custom vim
# Vim ~ /. Vimrc
Input:
Set nu
Set history = 10
In addition, there are also vim cursor positioning...
Old to learn, Mark, learning notes
In the Linux desktop environment, there is a gedit text editor and graphical interface (equivalent to Windows notepad)