The use of the Vim editor for the Linux learning path

Source: Internet
Author: User

This chapter describes the use of the VIM editor

The Vim editor is an enhanced version of the VI editor

Vim is a full-screen editor, a modal editor, called a modal editor, because Vim has multiple modes.

The following are the main three modes of VIM:

Edit mode (also called command mode): In this mode you can complete string jump, string deletion, flip screen operation and so on

Input mode: Any characters entered in this mode will be saved in the file as part of the file

Last-line mode: In this mode, you can implement string search, string substitution and other operations


The VIM Editor's three modes of mutual conversion

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/30/5A/wKioL1OlgQbgdcJIAAEqrW7MMS8127.jpg "title=" ms.png "alt=" Wkiol1olgqbgdcjiaaeqrw7mms8127.jpg "/>


Mode conversion:

Edit mode--Input mode

I: In front of the character of the current cursor, converted into input mode

A: After the current cursor character, convert to input mode

O: Create a new row below the current cursor line and convert to input mode

I: Converted to input mode at the beginning of the line where the cursor is currently located

A: At the end of the line where the current cursor is located, convert to input mode

O: Create a new row above the current cursor line and convert to input mode

Input mode--edit mode

Press the ESC key to convert to edit mode

Edit Mode--last-line mode

Enter ":" in edit mode to enter the last line mode


Last-line mode--edit mode

Press the ESC key to convert to edit mode


Note: input mode and edit mode cannot be converted directly, and need to be converted by editing mode


Usage of VIM (application)

First, open the file

Vim [option] FILENAME

+#: The cursor is directly at the beginning of line # when opening a file

#: When opening a file, the cursor is directly at the beginning of the last line

+/pattern: When you open a file, the cursor navigates to the beginning of the line to which the first PATTERN matches


Second, close the file

1. Close the file in the last line mode

: Q exit

: Wq save and exit, equivalent to: x effect

: q! Do not save and exit

: W Save

: w! Force Save


2. Exit the file in edit mode

ZZ: Save and exit


Iii. movement of the cursor (operation in edit mode)

1, character-by-word movement

H: The cursor moves one character to the left

L: The cursor moves one character to the right

J: Move the cursor to the next line

K: Cursor moves to the previous line

#h, #l, #j, #k means the cursor moves # times at a time


2. Move in Word units

W: Jump to the beginning of the next word

E: Jumps to the ending of the current or next word

B: Jump to the beginning of the current or previous word

#w, #e, #b means the cursor moves # times at a time


3, in-line jump

0: Jump to the beginning of the line, absolute row beginning (that is, some lines preceded by a space, the cursor jumps to a space, not the first non-empty character of the line)

^: Jump to the beginning of the first non-whitespace character lines

$: Jump to end of line


4. Jump between rows

#G: Jump To Line #

G: Skip to the last line

jump in the last line mode, directly to the travel number


5. Turn screen operation

CTRL+F: Flip one screen down

Ctrl+b: Turn up one screen

Ctrl+d: Flip Down half screen

Ctrl+u: Flip up half screen


V. Delete a single character

X: Delete a single character at the cursor location

#x: Remove the # characters that are at the cursor and backwards


Vi. Delete command D

D commands are generally combined with jump commands

#d跳转符: Delete multiple

DD: Delete cursor in the row

#dd: Delete the line with the cursor and the total # line down

Note: Deleting a file using the D command is not actually deleted, but is saved in the memory buffer.

Delete command in last-row mode:

START,ENDD: Delete start line to end line

.: Indicates when the forward

$: Indicates the last line

+#: means to delete the line and the down # line (a total of #+1 rows)

$-1: The second line to the bottom



Seven, Paste command

P (lowercase): If deleted or copied as an entire line, paste to the bottom of the line where the cursor is located, or if you delete or copy a non-full row, paste

To the character behind the cursor

P (uppercase): if deleted or copied as an entire row, paste to the top of the line where the cursor is located, or if you delete or copy a non-full row, paste

To the front of the character where the cursor is


Eight, copy command y

Copy the P command and delete the D command syntax using the same, except that one is original copy, one originally deleted


Nine, modified characters: First delete the content, in the conversion into the input mode

The C command uses the same syntax as the D command.


Ten, character substitution

R: Character substitution

R: Enter replacement mode, in which multiple characters can be replaced at once


Xi. Undo Edit Operations

U: Undo Previous Edit Operation

continuous use of U command to undo previous n Operations

#u: Undo Recent # Operations directly


Undo the most recent undo operation (Restore the last undo operation)

Ctrl+r


12. Repeat the previous edit operation

.: Repeats previous edit operation


13. Visualization Mode

V: Select by character

V: Select by row


14. Find

:/pattern Backward operation

:? PATTERN Forward Lookup

N: Forward Lookup

N: Reverse Lookup


XV, find and replace

Use the S command in the last-line mode

start,ends/pattern/string/g Global Substitution

%: Full text


16. Use Vim to edit multiple files

Vim FILE1 FILE2 ...

: Next switches to the next file

:p Rev Switch to previous file

: Last switch to final file

: first switch to file one

QA: Exit All Files


17, split screen display a file

Ctrl+w,s Horizontal splitter window

Ctrl+w,v Vertical splitter window


Toggle Cursor in Window

Ctrl+w, up or down key

: QA Exits All windows


18, sub-window display multiple files

Vim-o FILE1 FILE2. Horizontal split Display

Vim-o FILE1 FILE2. Vertical split Display


19. Save some of the contents of the current file as another file

: Start,endw/path.to.somefile


20. Populate the contents of another file in the current file (added as an attachment)

: R/path/to/somefile


21. Interacting with the shell

:! command can no longer exit the file, use the shell command


22. Advanced application (operation in last line mode)

1. Display or suppress line numbers

: Set Number

: Set Nu shows line number

: Set Nonu suppress line numbers


2. Set the VIM editor to ignore or case sensitive

: Set ignorecase

: Set IC ignores case

: Set Noic Case sensitive


3. Auto Indent

: Set Autoinddent

: Set AI Auto Indent

: Set Noai Cancel Auto Indent


4. Check the found text highlighting or canceling highlighting

: Set Hlsearch highlighting

: Set Nohlsearch Suppress highlighting


5. Syntax highlighting

: Syntax on open syntax highlighting

: Syntax off syntax highlighting


If you want to make these commands permanent, you must write to the vim configuration file

The configuration file for Vim is divided into 2 types:

Global profile:/ETC/VIMRC Effective for all users

Personal profile: ~/.VIMRC only for specified users




















































This article from the "Linux Learning Path" blog, declined reprint!

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.