Common Vim commands

Source: Internet
Author: User
Tags first string

Labels: common Linux Vim commands

Zookeeper

First learned vim, see http://blog.csdn.net/u011848617/article/details/12837873

After that, I once lost my skills. After learning again, I found that it is essential to master Common commands. Below are some of the commonly used Vim commands I have compiled:


// The following operations are executed in command line mode:
/* Start Vim */
Vim ----------------------- specifies the file name when saving the file.
Vim filename ------------ open the specified file, which may or may not exist
VIM + N filename --------- enter vim, And the cursor stops at the beginning of line N.
VIM + filename ----------- enter vim, And the cursor stops at the beginning of the last line of the file
VIM +/string filename --- enter vim, And the cursor stops at the first string

/* Save the file and exit Vim */
W: --------- save the file being edited but do not exit Vim
W filename ----- Save the content of the current file to the new file specified by filename. If the file exists, an error is generated and VIM is not exited.
W! Filename ----- Save the content of the current file to the new file specified by filename. If the file exists, it overwrites the original file and does not exit vim.
Q: -------------- exit Vim without saving. If the file is changed but not saved, an error will occur.
Q! : -------------- Exit Vim without saving the file. If the file is changed, the changed content will be lost.
WQ: -------------- save and exit Vim

/* Move the cursor */
0 --------------- move to the beginning of the current row
$ --------------- Move to the end of the current row
W --------------- shift one word to the right
NW -------------- shift n words to the right
B --------------- 1 word left
NB -------------- shift n words left
(--------------- Move to the beginning of the sentence. If it is already at the beginning of the sentence, move it to the beginning of the first sentence.
) --------------- Move to the beginning of the next sentence
{--------------- Move to the beginning of the paragraph. If it is already in the beginning of the paragraph, move to the beginning of the paragraph
} --------------- Move to the beginning of the lower segment
G --------------- move to the first line of the file
G --------------- move to the last row of the file
/Word ----------- search (+ n -- continue searching next/+ n -- continue searching next)
X --------------- delete a character from the backend
X --------------- delete a character from the forward
Dd -------------- Delete the row where the cursor is located
YY -------------- copy the row where the cursor is located
P (lower case) --------- paste to the next line
P (uppercase) --------- paste the previous line
CTRL + R/. -------- repeat the previous operation
U --------------- Delete the previous operation
I --------------- insert from front of the character where the cursor is located
A --------------- Insert the cursor from the character
O --------------- insert from the next row of the row where the cursor is located
R --------------- replace character
: Q -------------- leave
: WQ ----------- save and leave
: Set nu --------- display the row number
: Set Nonu ------- cancel row number

// Search for text
? String <enter> --------- search for string
N ---------------------- repeat the file header
N ---------------------- repeat at the end of the file

// Text replacement
: S/oldstr/newstr ------------ replace oldstr with newstr in the current row, only once
: S/oldstr/newstr/g ------------ replace all the oldstr strings with newstr in the current row.
: 1, 10 s/oldstr/newstr/g -------- in 1 ~ 10 rows replace all oldstr with the string newstr
: 1, $ S/oldstr/newstr/g --------- replace all oldstr with the string newstr in the entire file.

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.