Common Vim commands

Source: Internet
Author: User
Run the vim command vimfilename # to open or create a file, and place the cursor in vim + nfilename # at the beginning of the first line to open the file, place the cursor in vim + filename # at the beginning of line n to open the file, and place the cursor in vim +/patternfilename # at the beginning of the last line to open the file, place the cursor in the first string matching pattern. vim-rfilename #

Enter 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 # the system crashes when vim is being edited last time, restoring filename
Vim filename1 filename2 # Open multiple files and edit them in sequence

Move cursor command

H # Move the cursor one character to the left
L # Move the cursor one character to the right
Space # Move the cursor one character to the right
Backspace # Move the cursor one character left
K or Ctrl + p # Move the cursor up a row
J or Ctrl + n # Move the cursor down a row
Enter # Move the cursor down a row
W or W # Move the cursor one word to the beginning of the word
B or B # Move the cursor to the beginning of the word
E or E # Move the cursor right to the end of a word j
) # Move the cursor to the end of a sentence
(# Move the cursor to the beginning of a sentence
} # Move the cursor to the beginning of a paragraph
{# Move the cursor to the end of a paragraph
NG # Move the cursor to the beginning of line n
N + # Move the cursor down n rows
N-# Move n rows above the cursor
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 that the number is zero. move the cursor to the beginning of the current row.
$ # Move the cursor to the end of the current row

Screen tumble command

Ctrl + u # flip to the first half 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 first part 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 # Replace the specified number of characters with the input text starting from the current cursor position
S # delete a specified number of rows and replace them with the input text
Ncw or nCW # Modify a specified number of words
NCC # Modify a specified number of rows

Copy, cut, and paste

# V # switch to VISUAL mode and move the cursor to select text
C # replace (Change)
D # Delete)
Y # Copy ("Yank ")
Yy # copy the current row
P # paste
. # Repeat the last operation

Delete Command

Ndw or ndW # n-1 characters starting at and following the cursor
Do # Delete to the beginning of a row
D $ # Delete to the end of a row
Ndd # delete the current row and the next n-1 row
X or X # delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.
Ctrl + u # delete text entered in input mode

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 last search command in the reverse direction
: S/p1/p2/g # Replace all p1 in the current row with p2
: N1, n2s/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

Option settings

All # List all options
Term # set the terminal type
Ignorance # case insensitive in search
List # display the stop table (Ctrl + I) and the end mark ($)
Number # display the row number
Nonumber # hide the row number
Report # display the number of changes made by the line-oriented command
Terse # display 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 vim from searching at both ends of the file and starting from the other end
Mesg # Allow vim to display the information that other users write to their terminal using write

Last-line command

: N1, n2 co n3 # copy 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
: W # save the current file
: E filename # open the file filename and edit it.
: Q # exit vim
: Q! # Do not save the file and exit vim
:! Command # execute shell command
: 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 and n2 are not specified, the entire file content is used as the command input.
: R! Command # place the output result of command to the current line.

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.