Shortcut to Vi/vim

Source: Internet
Author: User
Tags save file

1 Vi/vim keyboard diagram

2 text commentary

6 ways to enter edit mode:

I insert before the cursor

I insert at the beginning of the line

A after the cursor is inserted

A inserts at the end of a row

o Insert in next line

o Insert in previous line

Delete character

X Delete Current character

X Delete the previous character


Row operations

DD Delete When moving forward


5DD counting from the current line, deleting 5 rows

YY copy when moving forward

8yy copy currently starting at 8 lines

P Paste Paste


What does NewMail in/var/spool/mail/root mean in linux?

In this case, the contents of mail are just some normal system information or a more important error report. If you install the mutt, you can use this command to view the contents of the mail (with root login first), not installed in the words with Cat/var/spool/mail/root view (with root landing first).

Under normal mode
:%s/mmm/nnn/g from MMM to nnn in the entire file range. G=gloabal

/www search for the specified string www

: 3 cursor positioned on line 3rd

3 table

General 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

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

$

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)

General 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

Redo previous action (common)

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

N1,N2 W[filename]

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

Shortcut to Vi/vim

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.