Vim Editor for OPS Foundation--linux

Source: Internet
Author: User

Vim/vi is a very common text editor under Unix/linux, most of the machines have VI, on different machines commonly used in different variants of software which VIM is more useful also used more widely vim is the abbreviation of VI improved, indicating better VI This article said some of the more useful, more commonly used commands, if you can skillfully use these commands, you will find that editing files are very helpful, especially for the development of personnel, can quickly improve development efficiency.

Full Screen Text editor:

Vi:visual Interface

Vim:vi improved

It is a modal editor: There are many modes of work, mainly using three:

1. Edit mode (Command mode)--Default operating mode

2. Last-line mode

3. Insert mode (input mode)

(Alternative mode, visual mode)

Here is a brief introduction to Vim's basic operations:

First, open (file) mode:

1.vi/vim: Open the interface directly,

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/8E/BB/wKiom1jKO63ShfWsAAByqc-e-so499.png-wh_500x0-wm_ 3-wmp_4-s_3990881311.png "title=" Qq20170316151525.png "alt=" Wkiom1jko63shfwsaabyqc-e-so499.png-wh_50 "/>

2.vim File:file is present, open and place the cursor by default on the first line of characters, Flie does not exist, it is opened as a new file, if saved, the file is created, the file is not saved disappear;

3.vim +# file when the cursor is on line #;

4.vim + FILE: The cursor is positioned on the last line;

5.vim +/pattern/: Opens the file, positioning the cursor at the beginning of the line where the first PATTERN is matched, i.e. only the first match is completed.

Second, the closure method:

Closing of the last line mode:

: Q Direct Close does not save the changed content;

: Wq save and exit;

: w Save the modified content

: q! Force exit

: wq! For root, some read-only file modifications can be forced to save the exit;

The closing of the editing mode;

ZZ: Save and exit;

ZQ: Do not save exit;

Third, in the Vim editing mode, move the cursor;

1. Character-by-word movement:

1). ARROW

2). HJKL: Lower left top right

2. Move literally:

W: Move to the beginning of the next word;

E: Move to the end of the word

B: Move to the first word of the previous word;

3. In-line jump;

0: Absolute beginning of the line;

^: relative to the beginning;

$: Absolute line end;

4. Inter-row Jump:

#G: Move directly to Line #;

G: Move directly to the last line of the document;

GG: The first character of the first line;

Movement of the last-line mode cursor

: #直接移动至第 # line

: $ last line

Four, page turn/flip screen:

CTRL+F: Flip one screen down

CTRL+B: Flip One screen

Ctrl+d: Lower half screen

Ctrl+u: Upper Half screen

Five, character-by-word deletion:

X: Delete the character where the cursor is located;

X: Deletes a single character to the left of the cursor position;

Vi. the Universal Delete command in edit mode;

D: Delete all content that the cursor passes through, such as DG: Deletes all the contents of the row to the last line;

DD: Delete the line of the cursor, before you can add #, indicating the deletion of a total # line;

In the last line mode:

:d

: #d

: M,nd (deleted from M to Nth Row)

:., $ (current line. To end of row $ delete)

: m,+nd (delete n rows starting from m)


Vii. Paste commands in edit mode;

P: Paste right down;

P: Paste to the left upward;

Viii. Copy commands in edit mode:

Y: like D; Copy all the contents of the cursor;

Nine, the mode of switching;

1. Edit mode to last line mode:

: Enter command

and : Search, N and N, sequential and reverse lookup;

/: Top-down

?: Bottom-up

2. Last-line mode to edit mode:

ESC key

Enter key

Backspace key

3. Edit mode to input mode:

I:insert to the beginning of the line and into the input mode;

I:insert Insert the information before the cursor position;

A:apend; the cursor moves to the end of the line and enters the input mode;

A: Inserts a character after the cursor position;

O:otherline Insert a new row above the line where the cursor is located

o: Insert a new line below;

CC: Enter the input mode after deleting the whole line content;

C: Delete from the cursor position to the end of the line into the input mode;

S: Delete a character after the cursor, enter the input mode;

S: Delete the whole line into the input mode;

4. Input mode to edit mode:

ESC key

5. Edit mode to replace mode:

R: Enter

6. Replace mode to edit mode:

ESC key

7. Edit mode to Visual mode;

V: The rectangle is selected according to the character;

V: The rectangular selection according to the behavior unit;

Select to perform the copy delete operation;

Return to edit mode after completing the operation;

Note: All mode switching must be through the edit mode, the two non-editing modes can not directly switch between;

X. Replacement of orders;

R: A character that replaces the position of the cursor;

Xi. Undo Edit Operations

U: Undo a previous edit operation

Ctrl+r: Undo the most recent undo operation

12, repeat the previous editing operation;

.

13, the special last line command:

1. Display and cancel line numbering:

: Set Number-->set nu

: Set Nonumber-->set Nonu

2. Turn on or off character case sensitivity;

: Set Ignorecase-->set IC

: Set Noignorecase-->set Noic

3. Turn the Auto Indent feature on or off:

: Set Autoindent--set AI

: Set Noautoindent--set Noai

4. Turn on or off the find highlighting:

: Set Hlsearch No shorthand

: Set Nohlsearch--nohl

5. Turn syntax coloring on and off:

: Syntax off

: Syntax on

14. Content Replacement

Find replacements

/pattern Backward Search string pattern

? pattern searches forward string pattern

N Next match (if yes/search, then down next,? Search is up next)

N previous match (IBID.)

:%s/old/new/g Search entire file, replace all old with new

:%S/OLD/NEW/GC searches the entire file, replaces all old with new, and each time you confirm whether to replace

Vim also has a lot of commands that can be obtained through the command "Vimtutor" to help with the learning;

Vim Editor for OPS Foundation--linux

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.