Vi/vim Common operations

Source: Internet
Author: User
Tags save file

I. Buttons available in general mode

1. 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: The cursor moves up one character

L or RIGHT ARROW key: The cursor moves one character to the right

[Crtl] + [f]: Screen moves down one page, equivalent to [Page DOWN] button

[Crtl] + [b]: Screen moves up one page, equivalent to [Page UP] button

0 or function key [Home]: Move to the first character of this column

$ or Function key [end]: moves to the last face character of this column

G: Move to the last line of this file

NG: Move to Nth line of this file

GG: Move to the first line of this file, equivalent to 1G

N[enter]: Move the cursor down n rows

2. Find and replace

/word: Looking down for a string called word

? Word: Looking up a string called word

: n1,n2s/word1/word2/g: Find word1 string between N1 and N2, and replace the string with Word2

: 1, $s/word1/word2/g: finds the Word1 string from the first row to the last line and replaces the string with Word2

: 1, $s/word1/word2/gc: finds the Word1 string from the first row to the last line and replaces the string with Word2. and display the prompt character before the replacement to confirm to the user whether to replace

3. Delete, copy to paste

X, x:x to delete one character (equivalent to [Del] key), X to delete one character (equivalent to [Backspace] key)

DD: Delete the line where the cursor is located

NDD: Delete the down n line where the cursor is located

YY: The line where the cursor is copied

Nyy: The next n line where the cursor is copied

P, p:p paste the copied data on the next line of the cursor, p is pasted on the cursor line

U: Restore previous action

[Ctrl] + R: Redo Last Action

. : Repeats the previous action

Second, the general mode switch to edit mode of the available button description

I, I: Enter the insertion mode, I is inserted from the current cursor, I for the current row in the first non-whitespace space to start inserting

A, a: Enter the insertion mode, a is inserted from the next Word prompt the current cursor, a is inserted from the last Word prompt the line where the cursor is currently located

O, O: Enter insert mode, O to insert a new line from the next line where the current cursor is located, O to insert a new row from the previous line where the current cursor is located

R, r: into insert mode, R replaces only the character of the cursor at a time, and R will always replace the text of the cursor until the [ESC] key is pressed

Three, general mode switch to command-line mode available button description

: W: Writes the edited data to the hard disk file

: w! : Forces the file to be written if the file property is read-only.

: Q: Leave Vi/vim

: q! : Force leave does not save file

: Wq: Leave after saving

: wq! : Force save to leave

: W[filename]: Save edited data to another file

Vi/vim Common operations

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.