Linux Operating System Basics vi/vim command

Source: Internet
Author: User

Before introducing the Nano editor, Vi/vim is more powerful in functionality, so it is common to write scripts using the Vi/vim editor. Vim adds a more friendly editing interface to the VI and makes it easier to find errors.

It can also be called Modal Editor: Edit mode (Command mode), last line mode, insert mode (input mode), replacement mode, visual mode, and script editing with good combination of various modes.

First, the Vi/vim open way:

Vi/vim: Open the Vi/vim interface;

Vim File:file exists, then open and place the cursor by default on the first line of the character;

File does not exist, it is opened as a new file, if saved, the files are created, if not saved, the file disappears;

Vim +# File: Set the cursor at the beginning of line #;

Vim + file: The cursor is positioned at the beginning of the last line;

vim+/pattern/Open the file, and position the cursor to the beginning of the line where the first PATTERN match is done, i.e. only the first match is completed;

Ii. how vim is closed:

Closing of the last line mode:

: Q Directly close the Vim editor, do not save the content of the changes;

: q! mandatory exit but not save;

: W Save the modified content;

: Wq Save the modified content and close the Vim editor;

: wq! for root users, some of the read-only file changes can be forced to save and exit;

: w! compulsory preservation;

Editing mode is off:

ZZ Exit save;

ZQ exit does not save;

In Vim's edit mode, move the cursor:

Character-by-word movement;

arrow, up or down key;

command Hjkl, on some keyboards do not configure the upper and lower left and right keys to use, the front can be added number, #h向左移动 # characters;

moving verbatim;

W moves to the next word;

e moves to the end of the word;

B Go back to the top of the word;

In-line jump;

0 Absolute beginning of the line;

^ relative beginning of line;

$ end of line;

Inter-row jump;

#G直接将光标移动至第 # line;

g Move the cursor directly to the last line;

GG Moves the cursor directly to the first line;

Cursor movement in last-line mode:

: #将光标移动至第 # line;

: $ to move the cursor directly to the last line of the document;

Third, page:

ctrl+f down a screen forward;

ctrl+b up one screen back;

ctrl+d down half screen;

ctrl+u up half screen up;

Four, character-by-word deletion:

x Delete the character at the cursor location;

x Delete the single character to the left of the cursor position;

V. The universal Delete command in edit mode:

D: Delete all the contents of the cursor;

DD: Delete the line where the cursor is located;

In the last line mode:

: m,nd Delete the contents of M to n rows;

. Represents the row where the current cursor is located;

$ indicates a trailing line;

M,+nd starts at the line where the cursor is currently located, passing n rows;

Six, paste:

P: paste right down;

P: Paste to the left upward;

in the last line mode:

p;

Seven, the Universal Copy command in edit mode:

Copy all the contents of the cursor;

The usage is the same as the D command;

Eight, the mode of switching:

1. From edit mode to last line mode:

: Enter command;

and To find, N and n,n to indicate sequential lookups, n for reverse lookup;

Top-down

? Bottom-up

2. From the last line to the edit mode:

ESC key;

Enter key;

Backspace key;

3. From edit mode to input mode:

I move the cursor to the beginning of the line and enter the input mode;

I insert the information in front of the position without changing the position of the cursor;

A move the cursor to the end of the line and enter the input mode;

A inserts a character after the cursor position;

o Insert a row above the line where the cursor is located;

o Insert a row below the line where the cursor is located;

C Replace the whole line of content;

C Delete from the cursor position to the end of the line, and enter the input mode;

s remove a character from the cursor position and enter the input mode;

s replace the whole line of content;

4. From input mode to edit mode:

ESC key;

5. From edit mode to replacement mode:

R enters the replacement mode;

6. From replacement mode to edit mode:

ESC key;

7. From edit mode to Visual mode:

v character selection;

V Select entire row;

A copy or delete operation can be performed after the selection;

Just complete the operation and go back to edit mode;

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

Nine, replace the command:

R replaces only one character;

X. Revocation:

u: Undo a previous edit operation;

ctrl+r: Undo the most recent undo operation;

Xi. Repeat the previous edit operation:

.;

12, the special last line command:

1.:set number Displays line numbers->set nu;

: Set Nonumber Cancel line number->set Nonu;

2. Turn character case sensitivity on or off:

: 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 nohlsearch->nohl;

: Set Hlsearch;

5. Turn syntax coloring on and off:

: Syntax on;

: Syntax off;

13, Vimtutor:

called a vim instructor, we can practice various actions in vim by opening vimtutor.

Vi/vim editing commands in the small operation more, more practice, slowly skilled up good.


Linux Operating System Basics vi/vim command

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.