Get the App
SLTechnology News&Howtos  ›  Servers  › 

Unix basic tutorial 8 Editor vi

Shulou Source: shulou.com Published: 2022-06-03 02:48:52 11月17日 Update

1. Type

1) Line Editor: edit units for rows. Edit 、 e 、 ex

2) screen editor: edit units in characters. Vi 、 v 、 view

2 、 vi

1) Command mode

(1) cursor movement

(2) Delete, paste, and find text

(3) Command key

1. Cursor movement

Move the ←↓↑→ cursor left, down, up, and right

Move the h j k l cursor left, down, up, and right

^ move the cursor to the beginning of the line

Move the cursor to the end of the line

+ move the cursor down one line

_ move the cursor up one line

Move the spacebar cursor to the left

Move the return key cursor to the right

two。 Delete text

X Delete the character where the cursor is located

Dw deletes the cursor to the suffix

D delete the cursor position to the end of the line

Dd deletes the line of the cursor

Preceded by a number indicates that multiple units are deleted at the same time

3. Replace text

R character replacement command

Cw word substitution command

4. Search for text

/ the character you are looking for starts looking backwards with the current cursor.

-n continue searching backward

-N keep looking forward

? The current cursor starts to look forward

5. Auxiliary command

U cancel the previous command

. Repeat the previous command

J connects the next line to the end of the current line

After pasting the content deleted by the previous delete command to the current cursor, the following content moves backward.

6. Combined use

2dd/p delete paste (the previous number 2 can be changed)

2yy/p copy and paste

7. Save text

Wq saves and exits

W save, do not exit

W file is saved to the file file and does not exit

Q exit

: q! Forcibly exit, do not save

Exit ": wq"

2) text input mode

(1) enter text

(2) Command key

I insert text before the cursor

I cursor line beginning

An add text after the cursor

A cursor end of line

O add a new line under the line where the cursor is located

O add a new line above the line where the cursor is located

Esc exit

3) basic use

(1) vi file

(2) vi-r file was last modified but saved, recovery interrupted unexpectedly, continue to work

(3) after vi file1 file2 w is saved, n edits the next file

(4) vi-x file password

4) execute unix command in vi

(1) exclamation point! ! ls

(2) r! Remols put the contents listed by ls in vi (at the cursor)

(3) 2R! Embed the contents of the command in the second line

(4) Command line editing function ($set-o vi)

Tags: Cursor command text move location line content character unit location number file mode editor input accident function word password at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information macOS Apple MariaDB