Vim tips for use
Install, find packages
[email protected] ~]# which VI
/bin/vi
[Email protected] ~]# Rpm-qf/bin/vi
Vim-minimal-7.2.411-1.6.el6.x86_64
[Email protected] ~]# RPM-QF ' which VI '
Vim-minimal-7.2.411-1.6.el6.x86_64
[Email protected] ~]# RPM-QF ' which vim '
Vim-enhanced-7.2.411-1.6.el6.x86_64
[Email protected] ~]CD MNT
[[email protected] mnt] #rpm-ivh/mnt/packages/vim-minimal-7.2.411-1.6.el6.x86_64.rpm
[Email protected] mnt]# rpm-ivh/mnt/packages/vim-enhanced-7.2.411-1.6.el6.x86_64.rpm
Enhanced is an Extended version of VI, more powerful than the mini version
Vim Editor mode switch:
Command mode, command line mode, edit mode
Command mode:
Character manipulation
A after the current character is inserted
I currently insert
o insert a row down
A Line End insertion
I line Header insertion
O Insert a row up
x Remove one character backwards (r modifies a single character )
X Delete one character forward
U undo one step ; U undo All operations
Operation of the row
Home or header,end , or ^ end of line,
End Key or DD key Delete Row Ndd Delete N rows
yy copy row nyy copy N rows
P Paste the copied line
paste on P line
Word manipulation
DW Deletes a word and moves the cursor to the beginning of the word when it is deleted. Also, if the cursor is not at the beginning of the line, delete the letter of the word after the cursor
YW copy a word
Block operation
Big D or d+$ Delete to the end of the line d+^ Delete to the beginning
y+$ Copy to tail y+^ copy to First
ESC exits the current mode
V mode
1.Ctrl + V Enter edit mode
2. Move the cursor down or up
3.mark the beginning of the line to be annotated
4, then the I of the capital
5.insert an annotation, such as "#"
6.when you press ESC, all comments are made.
Ctrl+v-->i-->#-->esc
To delete multiple lines of comment:
Ctrl + V enters edit mode, moves the cursor down or up, selects the comment section, and then presses D to delete the comment symbol
VIM command line mode operation
:w saves save
: Q did not make any changes, quit quit
: q! modified, not saved, forced to quit
:Wq Save and exit
:wq! force Save and exit # For example ,/etc/shadow files are modified to belong to read-only files must be wq!
:sh can be used after command input
:se ic(ignorcase) ignores case
:se noai Auto Indent
tip:r----> Modify individual characters, do not need to enter the editing mode such as QQ remote to avoid the Esc key conflict to exit is remote the Desktop
Replace
:%s/this/that/ # The first this of each line is replaced by that one
DF # replace All this in the text with that
:1,5s/this/that/g # Replace the first line to the fifth row matches the content
:set Nu/nonu # Show line number cancel line number
/ forward lookup :/target n search down,n look up
:s/this/that/gc Remove Highlighting
:Noh or casually find a group of characters that are not
: W/root/newfile will tell you that the currently edited file is saved to the /root directory under the name newfile
: the E~install.log action will open the text directly for editing
: R/etc/filesystems reads the contents of other files and copies them to the current cursor location
:! ls Invoking system Commands
If you accidentally open the directory, you can exit directly.
Navigate to a line in vim:
GG Navigate to the beginning of the line
G Navigate to the last row, beginning of line
Vim opens multiple files:
#vim-o file1 file2 ctrl+ww switch between two files.
# in Uppercase o display left and right; lower case
customizing vim
#vim ~/.VIMRC
Input:
Set Nu
Set history=1000 ----------Specify the number of commands to page up and down
This article is from the "St1sk" blog, make sure to keep this source http://st1sk.blog.51cto.com/9837690/1636281
Vim Tips for use