Linux -- vim

Source: Internet
Author: User
Three modes of apt-getinstallvimvim: General mode editing mode command line vitest.txt entering general mode insert command commands & nbsp; purpose I insert text before the cursor I insert text at the beginning of the line a Insert text after the cursor A Insert text at the end of the line

Apt-get install vim
Vim has three modes: General mode, edit mode, and command line mode.
Vi test.txt enters normal mode
Press I, I, a, A, o, O to enter the editing mode
Insert command
Command function
I insert text before the cursor
I. start inserting text in this row
A insert text behind the cursor
A inserts text at the end of the row
O insert a new line under the cursor
O insert a new line to the cursor
Locating command
Command function
H shifts one character to the left
J. move one row down
K move one row up
L move one character to the right
$ Move to the end of the row
0 move to the beginning of the row
H move to the top of the screen
Move M to the middle of the screen
L move to the lower end of the screen
: Set nu
: Set nonu cancel row number
Gg to the first line
G to the last line
NG to n
: N to row n
Delete Command
Command function
X delete the character of the cursor
Nx delete the last n characters at the cursor location
Dd deletes the row where the cursor is located.
Ndd delete n rows
DG deletes the content from the row where the cursor is located to the end of the file.
D. delete the cursor from the position of the cursor to the end of the row.
: N1, n2d delete rows in the specified range
Delete Command
Command function
Yy and Y copy the current row
Nyy and nY copy n rows below the current row
Dd: cut the current row
Ndd cut n rows below the current row
P and P are pasted under or on the row where the current cursor is located.
Replace and cancel commands
Command function
R replaces the character at the cursor
R replace the character from where the cursor is located, and press Esc to end
U cancel the previous operation
Replace and cancel commands
Command function
/String: specify the string to be searched forward. run: set ic to ignore the case when searching. disable ignore case: set noic.
N searches for the next occurrence location of a specified string
: % S/old/new/g replace the full text with the old string in the full text with new
: N1, n2s/old/new/g replace the string within a certain range. Replace the old string from line n1 to line n2 with the new string.
 

Vi practical operations:
: Wq save and exit ZZ =: wq
: Wq! Force save and exit. only the file owner and root can save and exit.
: Q! Force exit
: W! Save and do not exit
: W/test/bak. bak save as the specified path
: R [file name] Import file
: N1, n2s/^/#/g n1 to n2 rows plus #
: N1, n2s/^ # // g n1 to the front of the n2 line # Remove
: N1, n2s/^ ///g n1 to the front of the n2 row add //
: N1, n2s/^ ///g n1 to the front of the n2 line // remove
Use AB to define conversion words
: AB mymail liruxing1715@sina.com defines the conversion word, when entering mymail, press enter or space to become a liruxing1715@sina.com]
: Unab mymail cancels the above definition
If you want to change the vim settings, such as the shortcut key, set the row number ...... And so on. vimrc can be set: vi ~ /. Vimrc
In. vimrc, enter: Note: You do not need to add:
Set nu
AB mymail liruxing1715@sina.com
...
Then we enter any file vi will find, will show the line number and mymail is the conversion word of the mailbox liruxing1715@sina.com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.