Daily command vim simple to use

Source: Internet
Author: User

Vim: visual interface Improved, a powerful text editor developed from VI, describes some simple ways to use the VIM command below.

Vim is a modal editor with the following three modes of operation: Edit mode (default), input mode, and last-line mode.

When we use VIM to open one or more text files, use the format: VIM [options] File File2 ..., the commonly used options are:

+#: Indicates that a text file has been opened so that the cursor is positioned to the beginning of line #

+/pattern: Indicates that the text file is opened so that the cursor is positioned at the beginning of the first line to which the pattern matches

-O: Indicates that the window is split horizontally after opening multiple text files

-O: Indicates that the window is split vertically after opening multiple text files

One, the conversion between modes:

Edit mode ==> Input mode:

I:insert, the input mode is transferred in front of the character of the current cursor;

A:append, appended, into the input mode at the rear of the character at which the cursor is currently located;

I: Enter the input mode at the beginning of the current line

A: The current line end is transferred into the input mode

O: Create a new blank line below the current line and go into input mode

O: Create a new blank line above the current line and go into input mode

Input mode ==> edit mode: Press the ESC key

Edit mode ==> last line mode: Press: Key

Last-line mode ==> edit mode: Press the ESC key or more

Second, VIM cursor jump

1, between the characters jump: H (left), J (Down), K (UP), L (right), when we add # to the front of the command (indicating a specific number) is to move the # characters at a time.

2. Jump between words: W (the beginning of the next word), E (the ending of the current or next word), B (the beginning of the word in the current or previous word), and the same as # in front of the command, means to move the # words one at a time

3. In-line movement: 0 (absolute beginning), ^ (first non-whitespace character at the beginning of the bank), $ (absolute line end)

4. Move between lines: #G (jump to Line #), G (tail line)

Third, vim command:

1. Character editing (edit mode)

X: Delete the character at the cursor location

#COMMAND: Remove the # characters at the cursor and right

D: Delete, combine cursor jump character, implement multi-character Delete

d$: Delete the current cursor at the end of the line

d^: Deletes the current cursor at the beginning of the line

DW: Delete the current cursor at the beginning of the next word

De: Deletes the current cursor at the current or next word ending

DB: Deletes the current cursor to the beginning of the current or previous word

DD: Delete Row

#dd: Delete # lines, starting at the line where the current cursor is located, delete # lines

Y: Copy (yank), combine cursor jump character, implement multi-character copy, use method with D command

P: Paste (paste)

P: The buffer store is pasted below the current line if the entire row, otherwise, is pasted at the rear of the current cursor

P: The buffer store is pasted above the current line if the entire row, otherwise, is pasted at the front of the current cursor

C: change, combined with the cursor jump character, to achieve multi-character modification, using the same method as the D command, and into the input mode

R: replace (replace), replacing a single character

U: Undo, Undo Last Action, #u则表示撤销 # Previous action

Ctrl+r: Cancels the last undo operation

.: Repeat Last Action

2. Close the file: (last line mode)

: q! Do not save the exit

: w! Force save (usually the root user does not have write permissions to perform such operations)

: Wq Save Exit

: X Save exit

: W/path/to/somefile File Save

3. Find and Replace: (in the last line mode)

Character Lookup:

/pattern: Find from top down to text according to pattern

N: See what's next to match

N: View the last match to the content

? pattern: Find from bottom to top according to pattern to text

N: See what's next to match

N: View the last match to the content

Character lookup substitution: How to: s/What to look for/replace with/(650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" spacer.gif "style=" border:1px solid rgb (221,221,221); background-position:50% 50%;background-repeat:no-repeat;/>ig), To find content that can use a pattern, replace it with a meta-character other than a back reference, and the delimiter can be specified as needed: [Email protected]@@, s###

I: Ignore character case

G: Global Substitution

Back reference: If you want to reference everything you want to find, you can use the & direct reference instead of adding \ (\) in the pattern, and if you only refer to what part of the pattern in the "What to find" matches, you still need to use regular expression groupings; then use \1, \2, ... To reference

Four, set the built-in variables (in the last row mode)

Use the SET command in the last row mode to define the value of a built-in variable as the desired value; if we need to make these settings permanent, then we need to save the settings to the configuration file:/ETC/VIMRC or ~/.VIMRC

: Set NU Displays line number

: Set Nonu suppress line numbers

: Set SM Toggle Highlight and Bracket matching function

: Set NOSM suppress highlighting and parentheses matching function

: Set AI Auto Indent

: Set Noai Cancel Auto Indent

: Set IC ignores character case

: Set Noic does not ignore character case

: Set Hlsearch search results display highlighting

: Set Nohlsearch Close search results display highlighting

: Syntax on to turn on the syntax highlighting function

: syntax off syntax highlighting function


Daily command vim simple to use

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.