Vi/vim Common Commands

Source: Internet
Author: User
Tags save file

Vi/vim Common Commands

Command mode

Cursor movement

h or left ARROW key

The cursor moves one character to the left

J or DOWN ARROW key

Move the cursor down one character

k or up ARROW key

Move the cursor up one character

l or right ARROW key

The cursor moves one character to the right

Ctrl+f

Screen forward one page (common)

Ctrl+b

The screen turns back one page (common)

Ctrl+d

The screen turns half a page forward

Ctrl+u

The screen turns half a page forward

+

Cursor moves to the next column of non-whitespace

-

Cursor moves to the previous column of non-whitespace

N<space>

When you press the number and then press the SPACEBAR, the cursor moves the n characters of the line to the right. For example 20<space>, the cursor moves to the right by three characters

0 (HOME)

(is the number 0) The first word to move to this line prompt (common)

$ (END)

Move to the last word of this line prompt (common)

H

The cursor moves to the top row of the screen

M

The cursor moves to the line in the center of the screen

L

The cursor moves to the bottom line of the screen

G

The cursor moves to the last line of the screen

NG

Move to the nth row of this file. For example 20G, it will be moved to the first line of this file (mate : Set Nu)

N<enter>

Move the cursor down n rows (common)

Command mode

Find and replace

/word

Find a string named word after the cursor (common)

? word

Look for a string named Word before the cursor

: n1,n2s/word1/word2/g

Find the word1 string between the N1 and n2 lines and replace the string with Word2(Common)

: 1, $s/word1/word2/g

Finds the word1 string between the first line and the last row and replaces the string with Word2(Common)

: 1, $s/word1/word2/gc

Finds the word1 string between the first line and the last row, replaces the string with Word2, and displays a prompt for the user to confirm (conform)before replacing (common)

General mode

Delete, copy, and paste

X,x

x to remove one character backwards,x to delete one character forward (common)

Nx

Remove n characters backwards

Dd

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

Ndd

Delete the down N column of the column where the cursor is located, for example,20dd deletes the column (common)

d1g

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

Dg

Delete all data from the column that contains the cursor to the last row

Yy

Copy cursor Line (common)

Nyy

Copy the down N column of the column where the cursor is located, for example,20yy is the Copy column (common)

y1g

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

YG

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

P,p

p Paste the copied data in the next column of the cursor,p is pasted on the cursor column (common)

J

Combine data from the cursor column and the next column into one column

U

Restore previous action (undo)

Edit mode

I,i

Insert: Inserts the input text at the current cursor position, already exists

A,a

Add: Input is started by the next character where the current cursor is located, and the existing character is backward (common)

O,o

Insert a new line: Enter characters from the beginning of the next line in the row where the cursor is located (common)

R,r

Replace:R replaces the character that the cursor refers to, andR will always replace the text indicated by the cursor until ESC is pressed (common)

Esc

Exit edit mode, return to normal mode (common)

Command-line mode

: W

Writing edited data to a hard disk file (common)

: w!

If the file property is read-only, force the file to be written

: Q

Exit VI(Common)

: q!

If you have modified the file, do not want to save, use ! do not save file for forced exit

: Wq

Exit after saving, if : wq!, exit after force save (Common)

: W[filename]

Save the edited data as another file (similar to saving a new document)

: R[filename]

In the edited data, read the data from the other file. The filename will be appended to the following line of the cursor

: Set Nu

Displays the line number, which, when set, displays the line number in front of each row

: Set Nonu

In contrast to ser nu , the line number is canceled

: Set Nohlsearch

Can be canceled highlighting, editable/ETC/VIMRC to edit cancel all highlighting

N1,N2 W[filename]

Save the contents of N1 to n2 as filename for this file

Vi/vim Common Commands

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.