Vim command Summary

Source: Internet
Author: User
Tags switch case

Preface

Vim is a super editor designed for programmers. It is incredibly powerful.

However, the learning curve is steep. I found a small chart on the internet two days ago, which is comprehensive. If you are familiar with the commands listed in the table,

It is enough to process the daily text, so post it for your reference.

Vim's cool-B lies not in its wide range of functions, but in its steep learning curve,

Most of these commands can be combined. For example, the 9yy command indicates copying 9 lines of content, and the 9 command indicates the number of lines to be copied,

Similarly, 100dd indicates deleting 100 rows. When numbers and commands work together, they are more powerful than simple commands,

Similarly, the C command indicates erasure, and W indicates word, and CW indicates erasure of a word,

C5w indicates that five words are deleted. Combine these simple commands,

You can make full use of unimaginable powerful functions and make your editing work fun.

Macro command (macros)

Some advanced editors will contain macro functions, which are certainly not missing in Vim. It is very convenient to use Macros in VIM:

 

: QX starts to record macros and saves the results to register x

Q exit record mode

@ X macro commands for playing records in the X register

After you enter QX in normal mode, all your edits to the text will be recorded,

If you enter Q again, the record mode is exited. Then, enter @ X to repeat the recorded command. After this command, it can be followed by a number,

Indicates the number of times to be repeated. For example, @ x20 can be repeated 20 times. This is very useful in text batch processing.

Edit multiple files at the same time

Among the many Vim plug-ins, there is a plug-in called minibuffer, which is called the tab function below. You can edit multiple files at the same time.

Tag command

 

: Tabe FN: edit the file FN in a new tab

GT switch to the next tab

GT switch to the previous Tab

: Tabr switch to the first tab

: Tabl switch to the last tab

: Tabm [N] Move the current tab to the nth Tab

Yes, as you think, it is similar to eclipse, ue, and other tabs!

Window command

 

CTRL + w s Horizontal Split Window

CTRL + W switch window

CTRL + w Q exit the current window (because there are multiple files at the same time, this command will not affect other Windows)

CTRL + W v Vertical Split Window

Others

Vim does not make actual changes to the file before saving, but only loads the file into the buffer. The editing of the file is actually the editing of the buffer. It will not be saved to the physical file until: W.

 

: E file: load the file to the new buffer.

: BN jump to the next Buffer

: BD Delete buffer (close file)

: Sp fn split the window and load FN to the new window

Exit Editor

 

: W write the buffer to a file, that is, save the modification.

: WQ: Save the modification and exit.

: X Save the modification and exit

: Q exits. If the buffer is modified, a message is displayed.

: Q! Force exit, discard Modification

Search and replace

 

/Pattern: returns the string pattern.

? Pattern: returns the string pattern.

N: Next match (If yes/search, it is the next one ,? Search to the next one)

N match (same as above)

: % S/old/new/g search the entire file and replace all old with new

: % S/old/new/GC search for the entire file, replace all old with new, and each time you want to confirm whether to replace

Copy and paste

Dd deletes the row where the cursor is located.

DW deletes a word)

X Delete the current character

X Delete the previous character

D. Delete it to the end of the row.

YY: copy a row. The command can be followed by a number to identify multiple rows. For example, 6yy indicates that six rows are copied from the current row.

Copy one word from YW

Y $ copy to the end of the row

P paste the clipboard content to the current row

P paste the clipboard content to the current row

] P is indented and VIM automatically adjusts the code indent.

"A puts the content into/into register a, and supports multiple clipboard

Note: for example, a common register is a system register named +. Therefore, the command "+ P,

Note that the plus sign (+) here does not represent the operator, and there are 21 registers.

Move cursor

In vim, the moving cursor is very different from other editors, but once learned, it will quickly move in the text.

 

H, J, K, L upper, lower, left, right

CTRL-f.

CTRL-B

% Jump to the brackets matching the current brackets. If the current value is {, the jump is to the matching value }.

W jumps to the next beginning and is separated by punctuation or words.

W jumps to the beginning of the next word and performs a long jump. For example, end-of-line is considered to be a word.

E. Jump to the end of the next word.

E. Jump to the end of the next character, Long Jump

B jumps to the previous word.

B jumps to the previous word, Long Jump

Jump from 0 to the beginning of the line, whether indented or not, that is, jump to 0th characters

^ Jump to the first character of the line

$ Jump to the end of a row

Gg jumps to the first line of the file

GD jumps to the declaration of the variable where the current cursor is located

[N] G jump to the nth line, such as 0g, is equivalent to Gg, 100th G is rows

FX finds x characters in the current row, and jumps

; Repeat the previous F command, instead of repeatedly inputting FX

TX is similar to Fx, but only jumps to the first character of X.

FX and FX are in the opposite direction

), (Jump to the previous or next statement

* Find the word where the cursor is located and look down

# Search for words at the cursor and search up

'. Jump to the previous editing position

Move on screen

 

H move the cursor to the top line on the current screen

M move the cursor to the middle line on the current screen

L move the cursor to the bottom line of the current screen

Bookmarks

 

Ma stores the current position as tag

'A jump to tag

Edit

 

R to replace one character

J. Connect the next row to the current row.

CC deletes the current row and enters the editing mode

CW deletes the current word and enters the editing mode.

C $ erase the content from the current position to the end of the row and enter the editing mode

S. Delete the current character and enter the editing mode.

S. Delete the row where the cursor is located and enter the editing mode.

XP exchanges the current and next characters

U undo

CTRL + R redo

. Repeat the previous edit command.

~ Switch case sensitivity, current character

G ~ IW switches the case sensitivity of the current word

Guiw converts the current word to uppercase

Guiw converts the current word to lowercase

> Move the current row to the right of a unit.

<Shifts the current row to one unit (one Tab character) to the left)

= Automatically indent the current row

 

Insert mode

 

I enter insert mode from the current cursor

I enters the insert mode, and the cursor is placed at the beginning of the line.

A append mode, after the current cursor

A append mode, with the cursor placed at the end of the row

O Add a new row under the current row and enter the insert mode.

O Add a new row to the current row and enter the insert mode.

ESC exit insert mode

Visual Mode

Mark text

V enters the visual mode, Single Character Mode

V enters the visual mode, and the row Mode

CTRL + V enter the visual mode, column mode, similar to the column mode of UE

O jump cursor to another endpoint of the selected block

U converts the content in the selected block to uppercase

O jump cursor to another endpoint of the block

Aw select a word

AB Selects all the content in the brackets, including the brackets themselves.

All content in brackets selected by AB

The content in the column selected by IB, excluding the brackets

Content in {} selected by IB, excluding {}

Actions on tags

 

> Block shifted to the right

<Move left

Y copy Block

D. delete a block.

~ Change the case sensitivity of block content

 

Well, this short table is mentioned here. Of course it covers a limited range, but as the title suggests,

The power of VIM is that these commands can be combined to reflect their powerful editing functions.

This document I found on the Internet is also posted by the way. You can refer to it at the same time.

If there is a chance, I try to find some examples to illustrate the usage of these commands in practice so that we can better use them and improve our work efficiency.


This article from the "Half city smoke sand" blog, please be sure to keep this source http://vabc1314.blog.51cto.com/2164199/1536581

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.