Linux Beginner's text editor (vi, VIM)

Source: Internet
Author: User
Tags save file

The philosophy of the Linux system is all documents, we usually need to fill in the content of the file is often used in the text editor before we learned the Nano editor, but the Nano editor features a single, not suitable for complex operations, this article will be the main learning function of the more powerful VI and VIM text editor. The VI and VIM editors are also known as modal editors, and typically perform a series of operations in several modes. Vi/vim has roughly the editing mode (command mode), the last line mode, the insertion mode (input mode), the replacement mode and the visualization mode. Here's how to do this:

⑴vi/vim Open mode: ① Open the interface of Vi/vim;

②vi/vim File:file exists then open the file and place the cursor in the first character of the first line; If the file does not exist as a new file open if the save file is created, the file is not saved disappear

③vi/vim + #FILE: Specifies that the cursor is positioned at the beginning of the # line when the file is opened, and if the number of rows positioned is larger than the entire document line, position the cursor directly at the beginning of the last line

④vi/vim + FILE: Positions the cursor directly at the beginning of the last line of the document;

⑤vi/vim +/pattern/: Opens the file and positions the cursor to the beginning of the line where the first PATTERN matches, i.e. only the first match is completed.

⑵vi/vim Shutdown Method:

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 changes to read-only files can be forced to save and exit;

: w! Force Save

Editing mode is off:

ZZ: Save and exit;

ZQ: Do not save exit;

⑶ in Vim's edit mode, move the cursor:

① character-by-word movement

1) ARROW

2) H: Cursor left;

J: Cursor down;

k: cursor upward;

L: Cursor right;

② Verbatim movement

W: Move to the beginning of the next word;

E: Move to the end of the next word;

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

③ in-line jump:

0: Absolute beginning of the line;

^: relative to the beginning;

$: Absolute line end;

④ between rows:

#G: Move the cursor directly to line #;

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

GG: Move the cursor directly to the first line;

⑤ cursor movement in last-line mode:

: # Move the cursor directly to line #;

: 1 Move the cursor directly to the first line;

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


⑷ Flip Screen

CTRL+F: Flip one screen down

Ctrl+b: Turn up one screen

Ctrl+d: Flip Down half screen

Ctrl+u: Flip up half screen


⑸ character-by-word deletion:

x: Deletes a single character at the cursor location;

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


⑹ the Universal Delete command in edit mode;

D: Delete all the contents of the cursor;

DH, DJ, DK, DL, Darrow, DW, DE, DB, DG, DGG

DD: Delete the line where the cursor is located;

In the last line mode:

:D: Delete the cursor in the row

: #d: Delete Line #

: m,+nd: Delete all rows starting with line m and passing through n rows;

: m,nd: Deletes all rows from the beginning of line m to the end of the nth line;

:., $d: Removes the line from the cursor to the last line of the document;

.: Indicates the line where the cursor is currently located;

$: Last line of document


⑺ the Universal Paste command in edit mode:

P (lower): Paste right down;

P (upper): Paste to the left upward;

In the last line mode:

P


⑻ the Universal Copy command in edit mode:

Y: Copy all the contents of the cursor;

The usage is the same as the D command.

YY: Copy the line of the cursor;


⑼ Mode 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 mode 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 character in front of cursor position;

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 new line above the line where the cursor is located;

o: Insert a new line below the line where the cursor is located;

CC: After deleting the entire line of content, enter the input mode;

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

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

S: After deleting the whole line, enter the input mode;

4. From input mode to edit mode:

ESC key

5. From edit mode to replacement mode:

R: Enter replacement mode

6. From replacement mode to edit mode:

ESC key

7. From edit mode to Visual mode:

V: The rectangle is selected according to the character;

V: The rectangular selection according to the behavior unit;

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

As soon as the operation is complete, return to edit mode;


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


⑽ Replace command

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

⑾ Undo Edit Operation:

U: Undo a previous edit operation;

Ctrl+r: Undo the most recent undo operation;

⑿ Repeat the previous edit operation:.

⒀ Special last-line command:

1. Display and cancel line numbering:

: Set number---: Set Nu

: Set Nonumber--: 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 Hlsearch

: Set Nohlsearch--: Nohl

5. Turn syntax coloring on and off:

: Syntax on

: Syntax off

⒁ using Vim to edit multiple files

1) Vim FILE1 FILE2 FILE3 ...

: Next to view or edit the contents of the latter document

:p rev to view or edit the contents of the previous document

: First to view or edit the contents of a document

: Last view or edit the contents of the Final Document

2) vim-o|-o FILE1 FILE2 FILE3 ...

-O: Horizontal split-screen display of multiple files

-O: Vertical split screen displays multiple files

Ctrl+w, ARROW

#Ctrl +w, ARROW

Ctrl+w, s displays a file horizontally on a split screen

Ctrl+w, v displays a file vertically on a split screen

⒂ populating the contents of other files into the current file

: R/path/to/somefile


Linux Beginner's text editor (vi, VIM)

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.