VIM Common operation

Source: Internet
Author: User

The vi Editor, the full name of visual interface, can perform numerous text operations such as output, delete, find, replace, and so on.
VI is not a typesetting program, it is not possible to arrange fonts, formatting, paragraphs, and other attributes.
VI is a full screen text editing program, no menus, only commands.
syntax: VI filename Opens or creates a new file filename and places the cursor at the beginning of the first line
vi +5 filename to open the file and place the cursor at the beginning of line five
vi + filename opens the file and places the cursor at the beginning of the last line
vi +/nimei filename opens a file and places the cursor at the beginning of the first match with Nimei
vi-r filename Opens the last time the system crashed with VI edit, the previous state was restored
3 different modes
command mode enters input mode: A adds after the cursor
A adds at the end of the line where the cursor is located
I insert before the cursor is added
I Insert at the beginning of the line where the cursor is added
o Add a row below the cursor line and enter the input mode
O Add a row on the line of the cursor and enter the input mode
input mode into command mode: ESC
The command mode enters the last line mode:
last-line mode enters command mode: ESC
operations in command mode
Copy/Paste
y copy
p Paste
Range
e The position of the cursor to the last letter of the word
W cursor position to the first letter of the next word
b The position of the cursor to the first letter of the previous word
$ cursor position to the last letter of the line
0 The position of the cursor to the first letter of the line
) cursor position to the first letter of the next sentence
(the position of the cursor to the first letter of the sentence
The position of the cursor to the last letter of the paragraph
{The position of the cursor to the first letter of the paragraph
GG moves to the beginning of the line
g move to the end
Delete/Modify
x Delete the character of the cursor
DD Delete the line where the cursor is located
R modifies the character of the cursor, and R is the character to be corrected.
R enters the replacement state, the input text overwrites the original data until you press ESC to return to command mode
s Delete the character of the cursor and enter the input mode
S Delete the line where the cursor is located, enter the input mode
cc To modify entire lines of text
u undo Last Action
. Repeat last Action
operations in the last-line mode
Find/Replace
You can use the: s command to replace a string in Vi/vim. The command has a number of different details of how to use the method, you can implement complex functions, record several here, convenient later query.
: s/vivian/sky/replaces the current line the first Vivian is Sky
: S/vivian/sky/g replaces the current line all Vivian are Sky
: N, $s/vivian/sky/replaces the first Vivian of each row in the nth row to the last row is Sky
: N, $s/vivian/sky/g replace the nth line to the last row all Vivian are Sky
N is a number, if N is., indicating the beginning of the current line to the last row
:%s/vivian/sky/(equivalent to: g/vivian/s//sky/) replaces the first Vivian of each line as Sky
:%s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all Vivian in each row as Sky
you can use # as a delimiter, at which time the middle/not as a delimiter
: s#vivian/#sky/# Replace the current row the first vivian/is sky/
:%s+/oradata/apras/+/user01/apras1+ (use + to replace/):/oradata/apras/Replace with/user01/apras1/
Save/Exit
Q Exit
W Save
x Save Exit
! Mandatory

VIM Common operation

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.