Vim Editor Commands

Source: Internet
Author: User
Tags save file

Install Vim

Apt-get Install Vim

Open a document with Vim vim XXX

There are three modes of vim:

Command mode: You can move the cursor, delete characters, and so on.

Insert mode: You can enter characters in this mode and press ESC to return to command mode.

Low-line mode: can save files, exit VI, set VI, Find and other functions (low-line mode can also be seen as a command mode).


One, open file, save, close file (used in VI command mode)

: w//Save File
: w vpser.net//Save to Vpser.net file
: Q//Exit editor, if the file has been modified please use the following command
: q! Exits the editor without saving
: Wq//Exit editor, and save file

Second, insert text or lines (vi command mode to use, after executing the following command will go into insert mode, press ESC to exit the insertion mode) general use I

A//Add text to the right of the current cursor position
I//Add text to the left of the current cursor position
A//Add text at the end of the current line
I//Add text at the beginning of the current line (the beginning of a non-empty character)
O//Create a new row above the current line
O//Create a new row below the current line
R//replace (overwrite) the current cursor position and several subsequent text
J//Merge cursor row and next line of behavior (still in command mode)

Third, move the cursor (used in the VI command mode)

1, use the upper and lower left and RIGHT arrow keys

2, Command mode: H left, J down, k up, l to the right.
Spacebar to the right, Backspace left, Enter to the next line,-move to the top of the line.

Iv. Delete, restore characters or lines (used in VI command mode)

X//Delete current character
NX//delete n characters starting from the cursor
DD//Delete when moving forward
NDD//Down Delete the current row, including n rows
U//Undo Previous action
U//Undo all operations on the current line

V. Search (used in the VI command mode)

/vpser//Search Vpser string under Cursor, Vpser can be regular expression
? vpser//Searching for vpser strings on the cursor
N//down searches for previous search action
N//Up search previous search action

* (#)//When the cursor rests on a word, entering this command indicates finding the next (top) word that matches the word. Again, enter N to find the next match, and enter N to search in the opposite direction.

g* (g#)//This command is similar to the previous command except that it does not exactly match the word at which the cursor is located, but rather matches all strings that contain the word.

Six, jump to the specified line (vi command mode use)

n+//Jump down N rows
N//Jump up N rows
NG//jumps to rows with line number n
G//Jump to the bottom of the file

Seven, set the line number (vi Command mode use)

: Set nu//Display line number
: Set Nonu//Suppress line numbers

Eight, copy, paste (used in the VI command mode)

YY//Copy the current line to the buffer, you can also use "Ayy copy," A is a buffer, a can also be replaced by any letter A to Z, you can complete multiple replication tasks.
Nyy//Copy the current row down n rows to the buffer, or you can use "Anyy copy," A is a buffer, a can also be replaced with any letter A through Z, you can complete multiple replication tasks.
YW//Copy the character from the beginning of the cursor to the ending.
NYW//Copy n words starting from the cursor.
y^//Copy the contents from the cursor to the beginning of the line. VPS Detective
y$//Copy the contents from the cursor to the end of the line.
P//Paste the contents of the Clipboard after the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."
P//Paste the contents of the Clipboard before the cursor, if the previous custom buffer is used, it is recommended to use the "AP to paste."

Ix. replacement (used in the VI command mode)

: S/old/new//Replaces the first occurrence of old in a row with new
: s/old/new/g//Replace all old in line with new
: n,m s/old/new/g//Replace all old from N to M with new
:%s/old/new/g//Replace all old in current file with new

X. Editing other documents

: E otherfilename//edit file named Otherfilename.

Xi. Modifying file formats

: Set Fileformat=unix//modify the file to UNIX format, such as win below the text file under Linux will appear ^m.

12. Find Help

When you don't know how to handle it, enter help directly to see the starting point of the documentation, ZZ is exited or: Q, not recommended

Find a command about a letter: Help x find a command about X .


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Vim Editor Commands

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.