Common vi commands

Source: Internet
Author: User

============================
Vi command
============================
Vi a.txt uses the vieditor to edit a.txt. If it does not exist, an empty file is created. The default mode is normal;
---
A (after the cursor) I (before the cursor) r (replace the cursor character) o (next line) A (end of the line) I (beginning of the line) R (same as r) O (the last line) can be changed from normal mode to edit mode

---
Esc can switch from edit mode to normal mode
---
: Enter the command mode in general mode, and enter commands such as cancel and save.
---
/Enter the command mode from the normal mode and search can be performed;
---
By default, the wq command keeps the file and exits;
The q command exits by default;
Q! By default, the command cancels modification to the file and exits;
---

==========
Normal Mode
==========
H or left arrow
J or down arrow
K or up arrow
L or right arrow

---
Ctrl + f flip forward
Ctrl + B flip back
Ctrl + d move forward half page
Ctrl + u flip half page
---
0 or home moves to the first character of the row
$ Or end move to the last character of the row
N <space> move n characters to the right
---
Move G to the last row
[I] Move gg to row I. If I is omitted, move it to row 1st,
N <Enter> move n rows down
---
= {Motion} apply motion to specify lines, the default motion is indenting,
E.g.
Gg = G apply indenting to whole file,
---
The first word after w
E. The end of the last word. (if it is in a word and is not the end of the word, it is the end of the current word ,)
First 1 word in B
---
/Word search down word
? Word search up
---
X deletes one item from the backend.
3x delete 3 from the backend
X delete 1 forward
4X delete four forward
---
Dd delete/cut the entire row
3dd delete/cut contains three rows down the current row

Dw delete/cut words
3dw delete/cut the three words to the right

D. move the cursor to delete/cut the character or line that the cursor moves. Enter d and move the cursor. If the cursor moves to the left, delete the 1 character on the left, to the right, delete the current character (equivalent to x). To the right, delete the current row and the previous row. To the right, delete the current row and the next row. to jump to the right, delete the two rows (including two rows) all rows,

---
Yy copy row
3yy includes the current row copying down 3 rows

Yw copies the second 1st words after the cursor. The current word of the cursor only copies the cursor and the subsequent part (instead of the entire word), and the second blank character after the cursor is also copied (if any ),
Copy the three words after the cursor in 3yw,
---
P paste under the current row
P paste on the current row
---
U undo
Ctrl + r redo
---
: I jump to line I
---
Ctrl + shift +> shift right current line
2 ctrl + shift +> shift right 2 line
Ctrl + shift + <shift left current line
2 ctrl + shift + <shift left 2 line

==========
Normal Mode ---> edit mode
==========
I insert characters before the current cursor
I insert characters before the beginning of the current line
---
A inserts a character behind the current cursor
A inserts characters at the end of the current row
---
O open a new line under the current line and insert characters
O open a new line on the current line and insert characters
---
R and R are about to replace the current character. After replacement, they are still in normal mode.

==========
Edit mode ---> normal mode
==========
Exit the editing mode and enter normal mode.
---

==========
General mode ---> Command Line Mode
==========
: Enter the command line mode
---

==========
Command Line Mode
==========
W save
W! Force save. Even a read-only file can be saved as long as the user has sufficient permissions.
Q: Exit vi. If the file has been changed and has not been saved, an error is returned;
Q! Cancel modification and exit vi
Wq save and exit
Wq! Force save and exit
---
W B .txt: the original document is B .txt.
---
R c.txt adds the content of c.txt to the cursor in the current document,
---
Set nu display row number
Set nonu cancel row number
---
Set ai auto indent
Set noai does not auto indent
---
Set list displays the tab and line tail characters. The tab is represented by ^ I, and the line tail is represented by $,
Set nolist does not display tab and line tail characters,
---
Set tablestop = x to set the tab size,
---
Set all view current settings
---
Help [command] displays help. Use: q to exit the help.

---
N switch to the next file
E # Switch to the previous file
---
[A, B | %] s/xx/yy [/gic]
Replace xx with yy,
A B specifies the start and end line numbers respectively. If not specified, it takes effect on the current row by default. indicates the current row, $ indicates the last row, and % indicates all rows.
G indicates replacing all the matches. If g is not specified, only the 1st matches in each row are replaced,
I indicates case insensitive. If I is not specified, it is case sensitive,
C Indicates whether to confirm each replacement. If c is specified, confirm each matching replacement. Enter y or n for confirmation,
Wildcard characters are supported. special characters must be \ escape characters, such \.,

Example:
S/xx/yy: replace 1st xx in the current row with yy
10, $ s/xx/yy: replace 10th xx in each row with yy
% S/xx/yy/g replace all xx values in all rows with yy
% S/\./y/g replace all. In all rows with y
% S/\\+ // g replace all consecutive spaces with one space,
% S/tesT/abcdef/gi replace all test (Case Insensitive ),
% S/test/abcdef/gc replace all the tests. Each replacement requires confirmation,

==========
General mode ---> Search Mode
==========
/Search down
? Search up
N next place
Shift + n

---

Author: "java-2007"
 

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.