Vim common command collection

Source: Internet
Author: User
Run the vim command: vimfilename: to open or create a file, place the cursor on the first line of vim + nfilename: to open the file, and place the cursor on the first line of vim + filename: open the file, place the cursor in the first line of the last line vim +/patternfilename: open the file, and place the cursor in the first string matching pattern vi

Run the vim command:

Vim filename: open or create a file and place the cursor at the beginning of the first line
Vim + n filename: open the file and place the cursor at the beginning of line n
Vim + filename: open the file and place the cursor at the beginning of the last line
Vim +/pattern filename: open the file and place the cursor at the first string matching pattern
Vim-r filename: a system crash occurred when vim was being edited last time, restoring filename
Vim filename .... Filename: open multiple files and edit them one by one

Vim configuration:
All: lists all options.
Term: Set the terminal type
Ignorance: case insensitive in search
List: displays the stop table (Ctrl + I) and end mark ($)
Number: displays the row number.
Report: displays the number of changes made by line-oriented commands.
Terse: displays brief warning information
Warn: NO write information is displayed if the current file is not saved when it is transferred to another file.
Nomagic: Allows you to use special characters without "\" in search mode.
Nowrapscan: prohibit vi from searching at both ends of the file and starting from the other end.
Mesg: allows vi to display the information that other users write to their terminal using write.
: Set number/set nonumber: show/do not show row number
: Set ruler/set Northeasters: Display/do not display the ruler
: Set hlsearch highlight the searched words
: Set nohlsearch disable highlighted display
: Syntax on # syntax highlighting
: Set nu # display the row number
: Set tabstop = 4 # set the tab size
: Set softtabstop = 4
: Set autoindent # Auto Indent
: Set cindent # automatic indent in C language format

Move the cursor:
Up: k nk: Move n rows up
Bottom: j nj: Move n rows down
Left: h nh: Move n columns to left
Right: l nl: Move n columns to the right
Space: Move the cursor one character to the right
Backspace: Move the cursor one character to the left
Enter: move the cursor down a row
W or W: move one word to the beginning of the word to the right of the cursor.
B or B: move one word left to the beginning of the word
E or E: move one word to the end of the word to the right of the cursor.
): Move the cursor to the end of the sentence.
(: Move the cursor to the beginning of the sentence.
}: Move the cursor to the beginning of the paragraph
{: Move the cursor to the end of the paragraph
N $: Move the cursor to the end of line n
H: Move the cursor to the top line of the screen
M: Move the cursor to the middle line of the screen
L: Move the cursor to the last line of the screen
0: (note the number is zero) move the cursor to the beginning of the current row
^: Move the cursor to the first non-empty character in the line
$: Move the cursor to the end of the current row
Gg can be moved to the first line
G move to the last row
F: Move the cursor to character a of the current row.
F: Opposite
%: Move to the matching brackets (), {}, [], <>, and so on.
NG: Move to row n
G: to the last line

Screen tumble command:
Ctrl + u: half screen at the beginning of the file
Ctrl + d: Flip the half screen to the end of the file
Ctrl + f: flip the screen to the end of the file
Ctrl + B: flip the screen to the beginning of the file
Nz: Rolls row n to the top of the screen. if n is not specified, the current row is rolled to the top of the screen.

Insert text commands
I: before the cursor
I: At the beginning of the current row
A: After the cursor
A: At the end of the current row
O: open a new row under the current row
O: open a new row above the current row.
R: replace the current character
R: replace the current and subsequent characters until you press ESC.
S: starting from the current cursor position, replace the specified number of characters with the input text
S: Delete a specified number of rows and replace them with the input text
Ncw or nCW: modify a specified number of characters
NCC: modifies a specified number of rows.

Delete Command
X or X: Delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.
Dw: Delete a word
Dnw: delete n words
Dne: Yes, but it is deleted to the end of the word.
Do: delete to the beginning of a row
D $: delete to the end of the row
Dd: Delete a row
Ndd: delete the current row and the next n-1 row
Dnl: delete n letters to the right
Dnh: delete n letters from the left
Dnj: delete n rows down
Dnk: delete n rows up
Cnw [word]: Change n words to word
C $: change to the end of the row
Cc: change the entire line
Shift + j: delete the line break at the end of the line. The next line is connected.

Copy and paste:
P: paste the text deleted with x or d.
Ynw: copy n words
Yy: copy a row
Ynl: copy n characters
Y $: copy the current cursor to the end of the row
Nyy: copy n rows

Undo:
U: undo the previous operation
Shif + u (U): cancels all operations on the row.

Search and replace commands:
/Pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Search for pattern from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.
Cw [newword]: replace with newword
N: continue searching
.: Replace
: S/p1/p2/g: Replace all p1 in the current row with p2. g indicates that the execution needs to be confirmed with c.
: N1, n2 s/p1/p2/g: Replace all p1 from line n1 to line n2 with p2.
: G/p1/s // p2/g: Replace all p1 files with p2.
: 1, $ s/string1/string2/g: replace string1 with string2 in the full text.

BOOKMARKS:
M [a-z]: Mark in the text. the mark number can be 26 letters of a-z.
'A: move to mark

Visual mode:
V: enter visual mode
V: Enter the visual mode of the row
Ctrl + v: in block operation mode, use o and O to change the size of the selected edge.
Insert the same content in all rows, such as include, move the cursor to the start position of the insert, press CTRL + V to enter VISUAL mode, select the module, and press I (shift + I ), insert the text to be inserted, and press [ESC ].

Command line:
: N1, n2 co n3: copy the content from line n1 to line n2 to line n3.
: N1, n2 m n3: move the content from line n1 to line n2 to line n3
: N1, n2 d: delete content from line n1 to line n2
: N1, n2 w! Command: The content from line n1 to line n2 in the file is used as the command input and executed
If n1, n2 is not specified, the entire file is used as the command input.

Macro:
Q [a-z]: the macro is used to start the record, and the macro can be named "a-z". Then, use q to terminate the recording macro.
Reg: displays all macros defined Currently. use @ [a-z] to execute the macro [a-z] at the current cursor.

Window operation:
: Split a window
: Split file. c: separates windows from another file. c.
: Nsplit file. c: separates the window for another file. c and specifies the number of rows.
Ctrl + w switch in the window
: Close the current window

Files and others:
: Q: Exit vi.
: Q! : Do not save the file and exit vi
: E filename: open the file filename and edit it.
: E! : Discard modifying the file content and reload the file for editing.
: W: save the current file
: Wq: the disk is logged out.
: ZZ: save the current document and exit VIM.
:! Command: execute shell command
: R! Command: place the output result of the command to the current line.
: N1, n2 write temp. c: write the n1 in this file to the n2 row into the temp. c file.
: Read file. c: Insert the file. c content under the current cursor
: 0 read file. c insert the content of file. c to the beginning of the current file (row 0th)
: Nread file. c insert the content of file. c to the end of row n of the current file.
: Read! Cmd: Insert the output of the external command cmd to the bottom of the current cursor.

Help:
: Help: view the help document. In this example, press CTRL +] to enter the hyper-connection, and press CTRL + O to return.
: Help subject: view the help of a topic. ZZ exits.

Other common features:
: Newtab new tag
: Gt go to the next tag
: GT to the previous tag
: Au GUIEnter * simalt ~ X maximize startup

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.