Instructions for using Vim

Source: Internet
Author: User

Instructions for using Vim

Vim is a rich and powerful text editor, and Vim is a text editor developed from VI. Its code completion, compilation and error jump and other convenient programming features are particularly rich, in the programmer is widely used.

Vim is very convenient to use: vim [options] [File ...]

1, vim can edit the specified file, you can also directly start the Vim editor for editing, for opening the specified file editing can be added to the option to more convenient operation, the common options are as follows:

+#: #表示数字, the cursor is at the beginning of line # when the file is opened

+/pattern: When opening a file, the cursor is at the beginning of the first line that is matched to the pattern

Vim + file: Directly opens the file and the cursor is at the beginning of the last line

Vim-b file: Opening file files in binary mode

vim-d file1 Fiel2: can open file1 and fiel2 at the same time and compare

Vim-m file: Open file files in read-only mode


2, the VIM work process has three kinds of modes, respectively:

Command mode: The operation of the keyboard in this mode is often understood as an edit command

Insert mode: You can enter text content in this mode

Last-line mode: Vim's built-in command-line interface, which can perform Vim's built-in commands in this mode

Switching between the three modes:

(1) By default, when entering vim is the command mode, from the command mode to the insertion mode, there are a variety of switching methods, respectively,

I: Enter at the cursor position

I: Enter at the beginning of the line where the cursor is located

A: Enter after the cursor is located

A: The line at the end of the line where the cursor is entered

O: Opens a new line entry below the line of the cursor

O: Opens a new line entry above the line where the cursor is located

(2) Command mode to last line mode: direct input colon (:) to cut into the last line mode

(3) Last line mode to command mode: Press ESC key to toggle

(4) Insert mode to command mode: Press ESC to toggle

(5) Insert mode cannot switch directly to the last line mode, you need to switch to command mode and then switch to the last line mode.


3, to exit the Vim editor, you must first switch to command mode to exit, exit mode has command exit and shortcut key exit two, the implementation method is:

Command exit: Enter the colon into the last line mode, and then execute the relevant command exit, the command has the following:

Q: Exit

q!: Force quit is not saved

WQ: Save and exit

wq!: Force Save and exit

X: Save and exit

W/path/to/somefile: Save to specified file

Shortcut key exit:

ZZ: Save and exit

ZQ: Do not save exit


4, the cursor movement in the command mode

(1) Jump between characters

H key or LEFT arrow: Move left

L-Key or right-click: Move Right

K Key or up key: Move Up

J Key or Next key: Move Down

At the same time, H, J, K, L also support digital jump:

#{j|j|k|l}: #表示数字, jump # characters, such as 5j means move down 5 characters

(2) Jump between words, support digital jump

W: The first word of the next word

E: The ending of the current or next word

B: The first word of the current or previous word

(3) Beginning line end jump

^: Jump to the first non-whitespace character at the beginning of a line

$: Jump to end of line

0: Jump to the beginning of the line

(4) Jump between rows

#G: #代表数字, jump directly to the beginning of line #

G: Jumps to the beginning of the last line

1G or GG: Jumps to the beginning of the first line

(5) Jump between sentences (with Dot (.) as delimiter), support digital jump

(: Jump to the previous sentence

): Jump to the next sentence

(6) Jump between paragraphs (with blank lines as separators), support digital Jump

{: Jump to previous paragraph

}: Jump to the next paragraph

(7) Flip screen operation

CTRL+F: Flip a screen to the end of the file

Ctrl +B: Flip a screen to the file header

Ctrl +D: Turn half screen at the end of the file

Ctrl +u: Turn half screen to file header


5, Command mode operation (The following # represents the number)

X: Delete the character at the cursor location

#x: Delete the # characters from where the cursor is located

D: Delete the command, combined with the cursor jump character use, delete the jump range of characters, such as w,b,e,$,0,^

D: Deleted from the current cursor position to the end of the line, equal to d$

DD: Delete cursor in the row

#dd: Delete the line at the beginning of the row where the cursor is located

P: Paste

P (lowercase): If the buffer is a whole row, paste it below the current cursor, or paste it at the end of the current cursor.

P (uppercase): If the buffer is a whole row, paste it above the current cursor, or paste it at the front of the current cursor where it is located

Y: Copy, combine cursor jump character use, copy jump range of characters, such as w,b,e,$,0,^

Y or yy: Copies the entire line of the row that the cursor is on

#yy: the line at which the cursor is copied starts at the bottom # line

C: Modify, the so-called modification is deleted first, and then converted to insert mode. use the cursor jump character to delete characters within the jump range, such as w,b,e,$,0,^

CC or C: Deletes the entire row of the cursor and switches to insert mode

#cc: Delete the line at the beginning of the line where the cursor is located and switch to insert mode

~: Converts lowercase characters where the cursor is located to uppercase

R: replaces the character at which the cursor is located, and can only replace one character at a time

R: Switch to replace mode, you can replace multiple characters, press ESC to exit the mode

U: Undo Previous Action

#u: Undo Previous # Operations

Ctrl+r: Undo the previous undo operation

.: Repeat previous action

#: Repeat the previous action # times


6, the operation of the last line mode

(1) Content delimitation (The following # indicates numbers)

#: The first few lines, such as in the last line mode enter #, and then press Enter the cursor will jump directly to the beginning of # line

#,#: Content from the left # line to the right of the # line

#,+#: Starting with the # line on the left, plus the contents of the right # line

.: When moving forward

$: Last line

%: Full text, equivalent to 1,$

/PAT1/,/PAT2/: From the first line that is matched to the pat1 pattern, to the line between rows that are first matched to the PAT2 pattern

#,/pat1/: From line # to the first line that is matched to the PAT1 pattern, all content

/pat1/,$: Start with the first line matched to the pat1 pattern, and everything between the last row

The use of content definition can be followed by editing commands, such as C, D, Y, S, etc., the role of the specified scope of the content of the relevant editing operations, and some editing commands need to be placed in front of the content, such as W, R

W/path/to/somefile: Saves the selected range of content to the specified file

R/path/from/somefile: Reads the contents of the specified file to the specified location

(2) Find

/pattern: Looks at the end of the file from the current cursor location

? PATTERN: Finds the file header from the current cursor location

If more than one match is found during the lookup, use n or N to aid in finding

N: Find next in the same direction as the command

N: Find Next with command in reverse direction

(3) Find and replace

S: Complete the Find and replace operation in the last row mode using the following method:

Content definition s/Find mode/content/modifier to replace

The lookup mode can be used to indicate that the content to be replaced cannot be used in a pattern, but can refer to the contents of the previous lookup mode, such as backward references such as \1,\2, and &, which represents the entire contents of a reference lookup, with a few modifiers:

I: Ignore case

G: Global substitution, by default, each row replaces only the first occurrence

GC: Global substitution, asking before each replacement

Find separators in substitutions/can be replaced with other characters that have not been shown in the pattern, such as [email protected]@ @gi, s## #gj等


7. Multi-file mode operation (multiple files are opened at one time)

: Next: Switch to the next file

: prev: Switch to previous file

: First: Switch to the initial file

: Last: Switch to final file

: Wqall: Save all files and exit

: Qall: Exit All Files

: Wall: Save All Files

8. Multi-window operation

Multiple files:

Vim-o file1 file2 ... : Split Multiple files horizontally

Vim-o file1 file2 ... : Split multiple files vertically

Single File:

Ctrl+w,s: Split a single file horizontally

Ctrl+w,v: Splitting a single file vertically

Operation between multiple windows:

Ctrl+w,arrow (top, bottom, left, right): Switch between windows

Ctrl+w,q: Canceling adjacent windows

Ctrl+w,o: Cancel All windows

9. Window Property Definition

: Set Nu: Display line number

: Set Nonu: Suppress line numbers

: Set AI: Enable auto Indent function

: Set Noai: Cancel Auto Indent function

: Set IC: Ignores character case

: Set Noic: Character case not ignored

: Set SM: Bracket Matching

: Set NOSM: Suppress brace matching

; syntax on: syntax highlighting

: Syntax off: Canceling syntax highlighting

: Set Hlsearch: Search highlighting

: Set Nohlsearch: Cancel Search highlighting

Changing the window properties in the last-row mode is only valid for the current VIM process and can be permanently enforced by modifying the configuration file as follows:

Global configuration file:/ETC/VIMRC

Single User profile: ~/.VIMRC


10. Visualization mode

Enter the letter V in the command mode to enter the visual mode, in this mode can be used in conjunction with the mobile key (such as W, (, {, $, arrows, etc.), the selected content can be deleted, copied, filtered, search and replace the operation.

V: Character-oriented visual view

V: line-oriented visual view

Ctrl + V: block-oriented visual view







This article is from the "Linux Operational Learning path" blog, please be sure to keep this source http://fengliang.blog.51cto.com/3453935/1837200

Instructions for using 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.