Linux 6-use vi and vim, and linux 6 vivim

Source: Internet
Author: User

Linux 6-use vi and vim, and linux 6 vivim

I. Three vi modes and mutual Switch

1. General Mode

1) move the cursor

You can use the arrow keys, Page Up, Page Down, Home, and End to move the cursor.

G, move to the last row of the file

1G, gg, move to the first line of the file

N <space>, shift n places to the right

N <enter>, move n rows down

 

2) Search

/Word search down

? Word search up

N forward to the next

N reverse: Next

 

3) Replace

Note that there cannot be spaces between the following commands

: N1, n2s/word1/word2/g replace word1 between line n1 and line n2 with word2

: 1, $ s/word1/word2/g replace word1 between the first row and the last row with word2

: 1, $ s/word1/word2/gc replace word1 between the first line and the last line with word2, prompting the user to confirm before replacement

 

4) Delete

Delete keys x, X, and delete

Nx deletes n consecutive characters

Dd deletes the entire row

Ndd: delete n rows down

Delete d1G to the first line

Delete dG to the last row

D $ Delete to the end of the row

D0 Delete to the beginning of a row

 

5) Copy

Yy copy row

Nyy copies n rows down

Copy y1G to the first line

Copy yG to the last line

Y $ copy to the end of the row

Copy y0 to the beginning of the row

 

6) Paste

P paste to the next line

P paste to the previous line

 

7) u restores the previous action

8) ctrl + r redo the previous action

9). Repeated action

 

2. editing mode

In normal mode, press I, I, o, O, a, A, r, and R to enter the editing mode.

Edit mode Press Esc to exit edit mode and enter Normal Mode

 

3. Command column Mode

Enter 『:/? "Any of the three buttons enters the command mode.

Press Esc to exit the command mode and enter Normal Mode

Common commands

: W write

: W! Write only when read-only, never. Whether or not the file can be written depends on the file permission of the file.

: Q left

: Q! Force exit, not archived

: Wq storage left

: W filename saved separately

: R filename read another document

: Set nu display row number

: Set nonu does not display row numbers

 

Ii. features and applications of vim

1. Color Display

 

2. Block Selection

If you select the v character, the cursor is reversed!

If you select row V, the rows with the cursor passed are reversed!

[Ctrl] + v block selection, you can use a rectangle to select materials

Y copies the anti-whitelist.

D. Delete the anti-whitelist.

 

3. Multi-file editing

: N: edit the next file

: N: edit the previous file

: Files: Lists All files currently enabled by vim.

 

4. Multi-Window editing

: Sp [filename] opens a new window. If filename is added, a new file is opened in the new window. Otherwise, the two windows are the same file content (synchronously displayed ).

[Ctrl] + w + ← the cursor can be moved to the lower window.

[Ctrl] + w + ← the cursor can be moved to the upper window.

 

Iii. vim Configuration

We recommend that you create ~ /. Vimrc to configure the vim operation environment, such

Vim ~ /. Vimrc "the double quotation marks (") of this file are comments

Set hlsearch "High Brightness anti-white

Set backspace = 2 "can be deleted at any time with the backspace key

Set autoindent "automatic contraction

Set ruler "to display the status of the last row

Set showmode "the status of the row in the lower left corner

Set nu "displays the row number at the beginning of each row!

Set bg = dark "displays different background colors

Syntax on "performs syntax check and colors are displayed.

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.