Vim Common operation

Source: Internet
Author: User

Translated from: http://blog.163.com/stu_shl/blog/static/599375092011639354090/

First, the cursor movement

h or LEFT ARROW key (←)

20h or 20 (←)

The cursor moves one character to the left

The cursor moves 20 characters to the left,

J or DOWN ARROW key (↓)

20J or 20 (↓)

Move the cursor down one line

Move the cursor down 20 lines,

K or Up ARROW key (↑)

20k or 20 (↑)

Move the cursor up one line

The cursor moves up 20 lines,

L or right ARROW key (→)

20l or 20 (→)

The cursor moves one character to the right

The cursor moves 20 characters to the right,

One thing to note here is that you don't use the keypad to enter numbers, or you will enter the pattern directly .

Ctrl + F

Screen "Down" to move one page, equivalent to [PAGE DOWN] key (common)

Ctrl + b

Screen "Up" to move one page, equivalent to [PAGE UP] key (common)

Ctrl + D

Screen "Down" to move half a page

Ctrl + u

Screen "Up" move half page

Ctrl + E

Screen "Down" to move one line

Ctrl + y

Screen "Up" to move one line

+

Cursor moves to the next column of non-whitespace

-

Cursor moves to the previous column of non-whitespace

N<space>

That n means "number", press the number and then press the SPACEBAR, and the cursor moves the n characters of the line to the right. For example 20<space>, the cursor moves 20 character distances to the back.

N<enter>

N is a number. Move the cursor down n rows (common)

0 or function key [Home]

Move the cursor to the front of the next line and go to the insert State

$ or Function key [End]

Move to the last face of this line prompt (commonly used), where the $ in the regular is the meaning of the end, so that understanding can remember

H

The cursor moves to the first character of the line at the top of the screen, h you write it down as theabbreviation for the header, so it's okay to remember

M

The cursor moves to the first character of the line in the central of the screen, andm you write it down as middle abbreviation.

L

The cursor moves to the first character of the line at the bottom of the screen,l you write it down as the last abbreviation.

G

Move to the last line of this file (common)

NG

N is a number. Move to the nth row of this file. For example, 20G will move to line 20th of this file.

Gg

Move to the first line of this file, equivalent to 1G Ah! Common

Second, delete, copy, paste, revoke

X, X

In one line of words, X is the backward deletion of a character (equivalent to the [Del] key), and X is to delete a character (equivalent to [backspace], which is the backspace) (common)

Nx

Nx

N is a number that continuously deletes n characters backwards. For example, I want to continuously delete the 10 characters after the cursor, "10x".

N is a number that continuously deletes the n characters preceding the cursor. For example, I want to delete the 10 characters before the cursor, "10X".

Dd

Yy

Delete the entire line where the cursor is located (common),

Copy the line on which the cursor is located (common)

Ndd

Nyy

N is a number. Delete the row where the cursor is down n rows, for example 20DD to delete 20 rows (common)

N is a number. Copy cursor row down n rows, for example 20yy copy 20 rows (common)

d1g

y1g

Delete all data from the row to the first row of the cursor

Copy all data from the row to the first row of the cursor

Dg

YG

Delete all data from the row to the last row of the cursor

Copy all data from the row to the last row of the cursor

d$

y$

Delete the cursor to the last character of the line

Copy all data at the end of the line with the same character as the cursor

D0

Y0

That's 0 of the number, remove the cursor, and go to the front of the line.

Copy all data from the same character as the cursor to the beginning of the line

P, p

P Paste the copied data to the next line of the cursor, p paste the copied data to the previous line of the cursor

J

Combine data from one row of the cursor to the same line

C

Repeatedly delete multiple data, you can use the up and down keys to decide to delete the cursor above, or the following

U

Revoke. Common

Ctrl + R

Revocation of withdrawal. Common

Third, block selection, find, replace

character selection, the cursor will pass through the place anti-white selection!
v line selection, the line of the cursor will be reversed white selection!
ctrl + v block selection, you can select the data in rectangular way
y Copy the anti-white place.
d Remove the anti-white area
/string

Span style= "font-family: Young round; font-size:18px; " >?string

look under the cursor for a name called string string

Span style= "font-family: Young round; font-size:18px; " > look above the cursor for a name called string string

n

n

reverse lookup, the search string, can be understood as not Next

: n1,n2s/string1/string2/g The N1 here is the number of start rows to find, and N2 is the number of rows to find the end. ": 2,7s/ddd/fff/g" in line 2nd, line 7th, replace DDD with FFF
: 1, $s/string1/string2/g Look for the string1 string from the first line to the last line, and replace the string with string2! Common
: 1, $s/string1/string2/gc Look for the string1 string from the first line to the last line, and replace the string with string2! and display the prompt character before the substitution to the user to confirm (confirm) whether need to replace! Common

Iv. saving, exiting, environment variables

: W

: w!

Write the edited data to the hard drive archive (common)

If the file property is read-only, the archive is forced to be written. However, in the end can be written, or with you on the file permissions related Ah!

: Q

: q!

Leave VI (Common)

If you have modified the file, do not want to store, use! Do not store files for forced departures.

: Wq

: wq!

Left after storage

Forced to leave after storage

Zz This is the capital Z! If the file does not change, then do not store away, if the file has been changed, then save and leave!
: w [filename] Save As
: R [FileName] In the edited data, read the data from another file. The file "filename" is also added to the following line of the cursor
:! Command Temporarily leave VI to command column mode to perform command display results! For example ":! Cat./test "To view the contents of the test file in the current folder in VI
I,i,a,a,o,o,r,r Into the insert mode, although there are differences, the feeling is not very different, put together
Esc Exit insert mode, enter command mode
: Set Nu It is useful to show the line number, after setting it, to display the row number of the row in the prefix of each row, which is much more convenient when we modify the configuration file to know how many rows.
: Set Nonu In contrast to set Nu, cancels the line number

Vim Common operation

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.