Vim basic operations

Source: Internet
Author: User

1. VI Operation Mode
VI provides two operation modes: input mode (Insert mode) And command mode (Command mode). In input mode, you can enter text. In command mode, you can perform various editing actions, such as deletion and modification.

In input mode, press ESC keySwitch to the command mode.
In command mode Input commands (I, A, O, etc)Enter the input mode.

2. Access vi 

$ VI filename

Directly type "vi + file name to be edited" to edit the specified file.
If the specified file is a new file, the system prompts "New File". Otherwise, the current content of the file is displayed.

$ View filename

Open File filename in read-only mode

Three-Instruction Mode
3.1 enter input mode

A is input after the current cursor
A is input at the end of the current row
I input before the current cursor
I input at the beginning of the current row
O add a row under the current row and Input
O add a row above the current row and Input
After the input is complete, Press ESC to exit the input mode..

3.2 move cursor

H: move one character to the left
L move one character to the right
J. Move one character down
K moves one character up
B shifts one word to the beginning of the word.
W shift one word to the end of the word
0 move to the beginning of the current row
$ Move to the end of the current row
+ Move to the beginning of the next row
-Move to the beginning of the previous row
H move to the first line of the window
M moves to the middle row of the window
L move to the last row of the window
G move to the last line of the file
Ng is moved to line N of the document.
N + move n rows down
N-move n rows up

3.3 Windows Mobile

<Ctrl> + F
<Ctrl> + B windows, Volume One page
<Ctrl> + D windows half page
<Ctrl> + u windows
<Ctrl> + e windows to roll down a row
<Ctrl> + Y

3.4 delete operation

X Delete the cursor character
X Delete the first field of the cursor
DW deletes a word backward from the current position of the cursor
 DB deletes a word forward from the current position of the cursor
D0 is deleted from the beginning of the row to the current cursor position
D $ Delete the cursor from the current position to the end of the row
Dd deletes the row where the cursor is located.
D is the same as d $

3.5 modify operation

S: Modify the character of the cursor. Press ESC to finish the modification.
S. Modify the entire line. Press ESC to complete the modification.
R replaces the character of the current cursor
R enters the replacement status until the end of pressing ESC
CW modifies a word (from the cursor position to the end of the word)
CB modifies a word (from the beginning of the word to the cursor position)
CC modifies the entire line of content, and then press ESC to end, the same as s
C0 modifies the content from the beginning of a row to the cursor position
C $ modify the content from the cursor position to the end of the row
~ Switch the case sensitivity of the cursor's character

3.6 duplicate commands 
In command mode, you can add a number N before the command, and the command will be executed n times again. Common repeated operations include:

NX Delete n characters
NDD Delete n rows
NS modify n characters

3.7 cancel the previous action (UNDO)

U undo the result of the previous command

3.8 search for strings

/Search for the string from the current cursor.
? The string looks forward from the current cursor to this string.
N search for the Next string from the current cursor
N search for the Next string from the current cursor

3.9 view editing status

<Ctrl> + G: displays the file name being edited, the number of lines in the current cursor, the total number of lines in the file, and whether the file is modified.

4. Save and exit

: W: save, but do not exit
: WQ save and exit
: X same as: WQ
: Q: exit. If the current file is not saved, exit is prohibited.
: Q! Do not save and exit
: W file1 saves the content to file file1. note: the edited content is still the original file.
: W! File1 overwrites the content and saves it to the file file1. If the file file1 exists, W file1 will not be executed.

 

5. Environment Settings

: Set: displays the environment conditions that have been set.
: Set all show all environment setting options
: Set nu display row number
: Set Nonu does not display row numbers
: Set Ts = N set the length of the tab key to n

Six execution commands 
The following uses a specific number as an example to describe the number of rows. The row where the cursor is located can be replaced by ".", and the last row of the file can be replaced by "$.

: 10, 20 d Delete contents of rows 10th to 20th
: Delete 10th rows of content within 10 days
: % D delete all content
: 10, 20co30: copy the content from 10th rows to 20th rows after 30th rows
: 10, 20mo30 move the content from 10th rows to 20th rows after 30th rows
: 1, $ S/old/new replace the old from row 1st to the last row with the new
: 1, $ S/^/New Insert new before the content of row 1st to the last line
: 10 move the cursor to 10th rows

Seven repeated commands

. Repeat the previous command

Switch to shell status

: Sh switch to shell status, exit and return (Original address:
Http://www.cnblogs.com/endsock/archive/2010/12/29/1921127.html)
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.