Vim Common Operation Summary

Source: Internet
Author: User

On the command line: H command and character to view the meaning of the command and character

First, mobile

In normal mode

1.1. Moving and inserting

H move one column to the left

L Move Right one column

J Move down one column


K Move up one column


G the last line at the beginning;

GG first line at the beginning;

0 beginning of Line

^ Beginning of the line

$ End of line

W forward moves to the beginning of the next word, (skipping a space each time)

b Reverse moves to the beginning of the current word/previous word; (a string is found each time a space is skipped)

E forward moves to the end of the current word/next word; (the first character at the end of a word)

GE moves backwards to the end of the previous word

The EA is inserting after the end of the current word or the next word

The above W, B, GE, plus a after moving after inserting

I currently insert

C c. C $ Delete the cursor and insert the contents of the bank

c^ Delete the cursor to the beginning of the line and insert;

s CL deletes a character after the cursor and inserts

S ^c equivalent to DD delete when moving forward

I ^i Insert the current beginning

A $a insert the end of the current line

o a<cr> Insert blank line

1.2 in command-line mode

: 1 is the command mode input line number, jump to the corresponding line;

: $ jump to the end of the file;

: {Start},{end} for example:: 2,5p Prints the contents of lines 2nd through fifth. -

Second, find

In normal mode

The 1>f character line finds the next specified character (a single character) where it appears, and if found, moves the cursor directly there.

The command will repeat the search for the last character found by the F command.

F character in line to find the last character set

2> first put the cursor on the string, * then find, n will find the next place

Under the command line

:/character, after finding it, N will find the next place

:/\<\>,<8088> <ok>, you can limit the search character or the number,<> to match the bounds of the character

You can turn on very magic mode:/\v<8088> here the V is lowercase!

Third, replace

In command-line mode

:%s/content/copy/g replace content with copy globally

In normal mode

Iv. Revocation

The U key triggers the Undo command, which will undo the latest changes. One modification can be any action that changes the text within the document, including

Commands that are triggered in normal mode, visual mode, and command line mode

V. Delete

In normal mode

The DB cursor on the word can be reversed to remove the character before the word cursor

Example: The end is NIG|HT

Db

Result: The end is HT

DW is going to delete the character after the string cursor, with the b command to delete the entire word

Example: The end is NIG|HT

b The End is |night

DW the end is |

Daw Delete the entire word, first put the cursor to the word you want to delete there

Example: The end is Ni|ght

Daw the end I|s

d2w d3w Delete 2, 3 words in a positive direction

Vi. operator commands for modified VIM

The power of 6.1vim is largely based on the combination of operator and action commands. Double swords are invincible.

operator + Action Command = specific operation

DL is deleting one character

C Modification

D Delete

Y Copy to register (the line where the cursor is copied)

P paste the copied content;

g~ inversion case;

GU converted to uppercase;


Gu converted to lowercase;

> Increase Indent

< reduced indent

= Auto Indent

In command-line mode! Use external commands, such as system commands and shell scripts

\\{motion} Toggles the comment state of the line \\g the current line to the end of the file, \\\ comments out the current line.

\\ap will toggle the annotation state of the current paragraph; \\u

6.2 In insert mode: Ctrl+u at the beginning of the current line of the cursor,

Ctrl+w Delete a previous word

Ctrl+h Delete the previous character

Ctrl+u Delete from cursor to beginning of line

6.3 Delete and copy the established lines in the explicit row mode

: [Range] Delete [x] Delete the line within the set, [into register X] For example on the command line: 2,5 Delete remove 2 to 5 lines "

: [Range] yank [x] Copy the line of the formulation range [to register X]

: [Line]put [x] Pastes the contents of the register x after the specified line

: [Range] copy [line] copies the lines in the specified range below the line specified by lines;

: [Range] move [line] moves the row within the specified range below the line specified by lines;

: [Range] The row specified by the Join link

: [Range] Normal {commands} executes the normal mode command {commands} for each row in the specified range

: [Range]substitute/{partern}/{string}/[flags] replaces the place where {Partern} appears in the specified range with {string}

: [Range]global/{partern}/[cmd] matches the row of {pattern} to the specified range. Execute the ex command {cmd} on it

: in [Range]:., 5 current line to line fifth. :., $ range from current line to end of file

:%p, which represents all rows in the current file

:%s/practical/ptf/is to replace a "practical" in each line of the file with PTF,

:%s/practical/ptf/g all the "practical" in the text is replaced with PTF,

: {start},{end}: Before/

:/

Copying and moving rows in command-line mode commands

: Copy command (and its shorthand form: t) we can copy a range of rows from a document to a specified location

: Move command (and its abbreviated form: m) We can move a range of rows from a document to a specified location

: ' < Highlight selection's starting line

: ' > End row of highlighted selection

The setting and selection of the highlight area is vjj down in normal mode, VKK up the selected

Executes the normal mode command on the specified range, which can be followed by a series of commands in normal mode after normal

: Normal

Example: adding a symbol at the end of a specified line

: 2,5normal A; Add a semicolon after each line from 2 to 5, the default is the end of the line;

Inserts at the beginning of a specified line

: 2,5 normal ^i# inserted at the beginning of each line at 2-5 #

Repeat the last ex command @: in normal mode

Auto-Complete EX command

: Col ctrl+d

Colder ColorScheme

6.34 in insert mode

After ctrl+r =, enter calculated numbers and calculate symbols, insert the calculated results at the location you just inserted

Inserting very useful characters with character encoding

Ctrl+v{code} where code is a coded representation of a character or a number encoded

Note: In normal mode, the cursor is placed on a character GA (g+a) will encode the corresponding

7 Managing Multiple Files

7.1 Use shell commands conveniently on the command line.

Vim file

: Shell Enter

Enter a # system command line

When input exit returns VIM

:! {cmd} execute {cmd} in Shell

Example:!ls-al/usr/local/

: Read! {cmd} executes {cmd} in the shell and inserts its standard output below the cursor, which is the result output of the shell execution is inserted

: [Range]write! {cmd} executes {cmd} in the shell, even if the range content is placed in CMD and executed as a condition

: [range]! {filter} such as grep effect, for example: 98,101! grep Tomcat will remove rows that do not contain Tomcat.

7.2 Selecting a selection with a precise text object

Temporarily show/Cancel line numbers:

When you open a file with Vim, enter it in normal mode

: Set Number (or: Set Nu) Displays line numbers

: Set Nonumber (or: Set Nonu) cancels line number

In visual mode

var TPL =[

' <a href= ' {URL} ' >{title}</a> '

]

When using visual mode, one end of the selection is fixed to a specific character and the other end is free to move. The text object of Vim is composed of two characters, and the first character is always

is I or a.

I start with a text object that selects the inner text of the separator, and a text object that starts with a selects the entire text, including the separator

VI} or i{

Where in the mode of a pair of xml/html tags and content

It label Internal Xml/html label

You need to place the cursor in the relevant position of the label before it takes effect.

Performing operations with text objects in normal mode

{Start}

CI "#: Delete the contents of" "before inserting #

CIT Click here to first delete the contents of the middle of the XML tag and insert the subsequent string;

Range text objects can be used with other commands

IW current Word

AW current word and a space

IW Current String

AW current string and a space

is current sentence

As the current sentence and a space

IP Current Paragraph

AP current paragraph and a blank line

A) pair of parentheses

i) Other punctuation inside the parentheses and these 2 identical

The text content between it xml/html;

At xml/html content with labels and labels

When using visual mode, one end of the selection is fixed to a specific character and the other end is free to move. The text object of Vim is composed of two characters, and the first character is always

is I or a.

I start with a text object that selects the inner text of the separator, and a text object that starts with a selects the entire text, including the separator

VI} or i{

Where in the mode of a pair of xml/html tags and content

It label Internal Xml/html label

You need to place the cursor in the relevant position of the label before it takes effect.


Combination of 8 and regular expressions

8.1 Size-sensitive lookups

:/\c Dean ignores capitalization

:/\c DEAN Find by case

8.2 Follow regular Expressions

:/\v syntax pattern syntax and Perl approximate Perl syntax

:/\v the mode of large V to find the text in the literal sense. For example,/a.k.a such as backward also show that the escape method can be eliminated :/a\.k\.a

Here you can use:/\VA.K.A will search the a.k.a character itself, right/not working

\_s will match.

:/\zs Matches at any position, and sets the start of the match there:the

Next char is the first char of the whole match. |/zero-width|

Example:

/^\s*\zsif

Matches an "if" at the start of a line, ignoring white space.

Can is used multiple times, the last one encountered in a matching

Branch is used. Example:

/\ (. \{-}\zsfab\) \{3}

Finds the third occurrence of "Fab". The beginning of the boundary

:/\ze Matches at any position, and sets the end of the match there:the

Previous Char is the last char of the whole match. |/zero-width|

Can is used multiple times, the last one encountered in a matching

Branch is used.

Example: "End\ze\ (if\|for\)" matches the "end" in "endif" and

"ENDfor". End With what symbol

:/\v "[^"]+ "Match" quoted words "----not quote marks.

"[^"] the pattern uses 2 quotes as the starting and ending marker

:/\v "\zs[^"]+\ze "Match" quoted words "----not quote marks. The quotation marks themselves are excluded from the match, leaving only the referenced content

8.3 count the number of matches for the current pattern

:%s///gn Statistics match good, do not replace, that is, do not do a real replacement on the text


This article is from the "studious" blog, please be sure to keep this source http://eagleheart.blog.51cto.com/775380/1693338

Vim Common Operation Summary

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.