Ubuntu vi editor common actions (continually updated)

vi editor one text editor comes Ubuntu system, due to its non-visual features that are more difficult to Getting Started. Bloggers in this sort of part of the vi editor common commands for your reference, welcome to exchange or update.
vi editor three modes, where their usual describe each instruction.

1. Command Mode

Use the vi editor to open the file directly into command mode, which is as follows:

vi name.py

name for the file name, py file format (py here for an example).
In the command mode, the cursor position by the arrow keys to move.
Common commands:

dd: cursor to delete the entire line
xdd: starting from the cursor line, down to delete rows x

yy: copy the entire line cursor
xyy: starting from the cursor line, copy down the line x

p: The copy and paste the contents of the next line to
P: The copy and paste the contents on line

2. Edit mode

Edit mode can edit the contents of a file, you need to enter edit mode from command mode.
Instructions to enter the edit mode are as follows:

i: Inserts from before the cursor
a: Insert the cursor from

I: From the first cursor trekking Insert
A: Inserts from the cursor tail trekking

o: add content at the cursor line
O: add content in the row where the cursor

x: Delete backwards single character
X: delete a single character forward

You can freely edit the text to enter edit mode, To exit edit mode, press the ESC key to return to command mode.

Third, the line mode

Line mode is the mode of operation of the whole file, you need to go from command mode. After entering line mode, the cursor jumps to the bottom of the text.
The following way:

: wq to save and exit the editor
: q to exit without saving

: / 123 full-text search 123 characters

:% s / 123/456/123 Replace the text is from 456
: a, BS / 123/456/123 Replace the lines a and b is 456

In line mode. Press the ESC key to jump would command mode.

Published 17 original articles · won praise 10 · views 426

Guess you like

Origin blog.csdn.net/acslsr/article/details/103711746