Usage of three modes of VIM

Source: Internet
Author: User

Three modes of VIM
General mode

In this mode, you can: move the cursor up or down, delete a character, delete a row, copy, paste one line, or multiple lines.


Cursor movement in general mode

h or LEFT ARROW key The cursor moves one character to the left
L or RIGHT ARROW key The cursor moves one character to the right
K or UP ARROW key Move the cursor up one character
J or DOWN ARROW key Move the cursor down one character
Ctrl+f or PageUp key The screen moves forward one page
Ctrl+b or PageDown key The screen moves backward one page
Number 0 or SHIFT + 6 Move to the beginning of the bank
Shift + 4 Move to the end of our line
Gg Move to First line
G Move to Tail line
NG (n is any number) Move to Nth row


Delete, copy, and paste in general mode

X,x x remove one character backward, X to delete one character forward
Nx Remove n characters backwards
Dd Delete/Cut the row where the cursor is located
NDD (n is numeric) Delete/Cut cursor in row up to a total of n rows
Yy The copy cursor is in the row
P Paste the copied or pasted content from the line where the cursor is located
P Paste the copied or pasted content up from the line where the cursor is located
Nyy Copy n rows down from the line where the cursor is located
U Revert back action
V Moving the cursor after pressing v selects the specified character, which can then be copied, pasted, etc.


Edit mode
In general mode, it is not possible to modify a character, only to edit mode. From normal mode into edit mode, you can just press a key (I, I, A, A, O, O, R, R). When you enter edit mode, the words "insert or replace" appear on the bottom line of the screen (if your CentOS supports Chinese, "insert" appears). To return to normal mode from edit mode, simply click the ESC key at the top left of the keyboard.




I Insert in current word match either
I Insert at the beginning of the line where the cursor is
A Insert in current word specifier
A Inserts at the end of the current line
O Inserts a new row on the next line in the current row
O Insert a new row on the previous line in the current row




In normal mode, enter ":" or "/" to enter the command mode. In this mode, we can search for a character or a string, and we can save, replace, exit, display line numbers, and so on.




Find and Replace in command mode

/word Look for a string after the cursor to Word, press N to continue searching backwards
? word Look for a string before the cursor to Word, press N to continue searching
: n1,n2s/word1/word2/g Find word1 between n1,n2 rows and replace with Word2, and no G replaces only the first word1 of each row
: 1, $s/word1/word2/g Replace all word1 in the document with Word2, without G only replacing the first word1 of each line


Command mode other features

: W Save text
: Q Exit vim
: w! Force save, under root user even if the text is read-only can be saved
: q! Force exit, all changes are not valid
: Wq Save and exit
: Set Nu Show line Numbers
: Set Nonu Do not display line numbers


Usage of three modes of VIM

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.