Common vim commands, vim

Source: Internet
Author: User

Common vim commands, vim

VIM is generally divided into several modes to distinguish whether the input is a text or a command through different modes:
1. Normal mode (common mode, c-mode ):
Once you enter VIM, it is in c-mode. You can only enter commands and text. These commands may be commands for moving the cursor, editing commands, or searching for replacement commands.
2. Insert mode (I-mode ):
Press I/a/o to enter the I-mode. You can enter text in the editing area, and Press Esc to return to the c-mode.
3. Ed mode (common-line mode, e-mode ):
Press: enter e-mode. The VIM command prompt area (bottom of the editing area) has a colon: appears. You can enter the command line command and Press Esc to return to c-mode.
4. replace mode
Press R to enter the replacement mode, and Esc returns c-mode

Tips: the Esc key is frequently used in vim. You can change the function of the Esc key and the Caps key by modifying the registry.


Move the cursor between characters
K move up
H left shift (Backspace)
L right shift (Space key)
J move down

Move the cursor between words(The cursor can span rows. By default, a word is composed of letters, numbers, and underscores)
E e (end) is first moved to the end of the current word. If it is already at the end, it is moved to the end of the next word.
B (begin) reverts to the beginning of the current word. If it is already at the beginning, it is moved to the beginning of the previous word.
W w (word) is moved to the beginning of the next word. The punctuation marks are also considered a word, and spaces are not counted (equal to eb)
Note: uppercase commands ignore punctuation marks.


Move the entire row
0 move to the beginning of the current row
^ Move to the first non-blank location of the current row
$ Move to the end of the current row
+ Move to the beginning of the next line (shift + "= Key" in the primary key area, or Enter)
-Move to the beginning of the previous line
N | column n to the current row

Scroll screen (the cursor follows the code)
Ctrl + f (forward) scroll forward to a whole screen
Ctrl + B (backward) scroll back to a whole screen
Ctrl + d (down) scroll up half screen
Ctrl + u (up) scroll down half screen
Ctrl + e scroll down a row
Ctrl + y scroll forward a row

Use z to adjust rows
Z <Enter> move the row where the cursor is located to the top of the screen
Z. Move the row where the cursor is located to the center of the screen
Z-move the row where the cursor is located to the lower end of the screen

Move the cursor within the screen range (no scrolling)
H (hight) move the cursor to the row at the top of the screen
M (middle) moves to the row in the center of the screen
L (low) Move the row to the bottom of the screen
N rows down from nH to the top of the screen
Line n that nL moves to the top of the screen

Move the cursor based on text
%: Move the cursor to the brackets corresponding to the other half based on the current brackets of the cursor, including (,{,[

Move the cursor based on text blocks (not used for programming, used for editing)
Text blocks are sentences, paragraphs, and sections.
(Move to the beginning of the current sentence
) Move to the beginning of the next sentence
{Move to the beginning of the current paragraph
} Move to the beginning of the next section
[[Move to the beginning of the current section
] Move to the beginning of the next section
Among them, VIM uses? .! To mark a sentence, and to mark a paragraph with blank lines.

Move by row number
G move to the end of the text
Move gg to the beginning of the text
NG moves to line n (same as the n + enter command)
Ctrl + g VIM display area displays the complete information of the current row (from the root drive letter to the current row)
Tips:''Two SLR quotation marks can be returned to the position before G. Only one

Insert
Character position insertion
I insert before the cursor
I insert at the beginning of a row
A Insert after the cursor
A append at the end of A row
O open the new line insert in the next line of the cursor
O open a new line insert in the last line of the cursor
R replaces the cursor with a character

Merge rows
J. Merge the content of the next row into the current row with a blank space in the middle.

Character Deletion
X cut the character at which the cursor is located and does not automatically cross-line
X cut the first character of the cursor

Delete words
Dw is deleted from the character where the cursor is located to the start of the next word
De is deleted to the end of the word (punctuation is also a word)
DE is deleted to the end of the word (punctuation is not a word)
Delete db to previous word
DB is deleted to the previous word, including punctuation.

Delete row
Dd cut all contents of the row
D $ cut all content after the cursor position (inclusive) of the line (same as shift D)
D0 cut all content before the cursor position of the row (not included)

Search

* Match the current word of the cursor.
# Match the current word of the cursor
/Xyz search for the xyz string under the cursor
? Xyz search for the xyz string over the cursor
N next search Target
N previous search Target
: Set hls to enable highlight
: Set nohls disable highlight

Copy (y) and paste
Yw copies the characters starting from the cursor (inclusive) to the end of the word
Yb copies the characters starting from the cursor (not included) to the beginning of the word
Yy copy the current row to the cache
Nyy copies n rows down the current row to the buffer zone
Nyw copies n words starting from the cursor (punctuations count as one word)
Y ^ copy the content from the cursor to the beginning of the line (y $ to the end of the line)
P paste the content in the clipboard after the cursor
P paste the content in the clipboard before the cursor
Tips: contains and does not include the front (forward does not include the character of the current cursor, followed by the character of the current cursor)
In addition, you can mark the cache area to facilitate future reference and use double quotation marks:
"Ayy," byy, etc. When using "ap or" bp, paste different contents.

Replace
: S/old/new Replace the first old in the current row with new
: S/old/new/g replace all old in the row with new
: N, m s/old/new/g replace all the old values from n to m with new
: % S/old/new/gic replace all old in the current file with new, and c is confirm

Modify (c): delete the file first and then edit it.
Use the parameters following the c command to delete the corresponding content and modify the content in edit mode.
C or c $ modify the content after the cursor of the current row
C0 or c ^ modify the content from the cursor to the beginning of the current row
Cc or S to modify the current row
Cw modifies the character from the cursor to the end of the word (delete the word before entering the editing State)
Cfx or cFx modify the text from the cursor to the next character x
CFx modifies the text from the cursor to the previous character x.
CG indicates to modify the content of the current row to the end of the text
Tips:The data deleted by the c command has a buffer and can be pasted and used.

Repeated
. Repeat the previous command
N <command> repeat a command N times. The esc key executes the combined command. The enter key indicates that the cursor is wrapped.

10I * <esc>: enter 10 records at the beginning of a line *
5o ### <esc>: insert at the beginning of each row in the next five rows ###
5 h: Move left 5 times
N +: Jump n rows down
N-: Jump n rows up
Nx: Cut n characters starting from the cursor
3dd: delete 3 rows

Undo
U undo the previous operation, which can be executed multiple times
U undo all operations on the current row

Visual Mode
In visual mode, you can highlight the objects to be operated, and operate the entire selected text block.
V enters the character visualization mode. The unit of text is character.
V enters the line visualization mode, and the text is selected as the unit of action.
Ctrl-V or ctrl-Q to enter the block visualization Mode
Gv re-selects the text selected in the previous visualization Mode


In visual mode:

O move the cursor to the diagonal corner of the block area, and O moves to the horizontal side.
Vi [or vi 'or vi} selects the content of the entire [] or ''or {} Where the current cursor is located.
Va [or va 'or va} is the same as above, and the symbol itself will also be selected
Viw selects a word


Open/Save/exit/change the file
: E <path/to/file> to open a file
: W save the file
: Saveas <path/to/file> Save As <path/to/file>
: Wq save and exit
: Q! Exit and do not save
: Qa! Forcibly exit all the files being edited, even if other files are changed.
: Bn and: bp can open many files at the same time. Use these two commands to switch between the next or previous files.

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.