Summary of Linux vim editing commands

Source: Internet
Author: User
Tags control characters

1. Start the vim Compiler

Vim filename open the original file or create a new file.

Vim open a new file and specify the file name during or after editing.

Vim-r filename restores the files that fail to save the final editing result in time due to unexpected shutdown or terminal connection interruption.

View filename open the file in read-only mode. All the editing functions of view are the same as those of vim except that the final result of editing cannot be written to a file and saved.

2. cursor position command

Move cursor backward → move the cursor left, up, down, or right one character (ROW) position.

H j k l is the same as above.

-Move the cursor up a row.

Press Enter (or the plus sign "+") to move the cursor down a row.

The backspace key moves the cursor one character to the left.

The Space key shifts the cursor to one character position (command mode) on the right ).

Ctrl + F scroll down (the end of the file) to a screen.

Press Ctrl + B to scroll up the screen (in the beginning of the file.

Ctrl + D scroll down the half screen.

Ctrl + U scroll up the half screen.

Ctrl + E move the entire file content up in the editing window.

In the Ctrl + Y edit window, the entire file content is moved down one line.

W move the cursor one word to the right. The cursor stays at the beginning of the next word.

W move the cursor one word to the right. The cursor stays at the beginning of the next word (even if there is a punctuation between the two words ).

B. move the cursor to the left. The cursor stays at the beginning of the next word.

B. move the cursor to the left. The cursor stays at the beginning of the next word (even if there is a punctuation between the two words ).

E. move the cursor to the last character of the current word (or next word.

E is the same as above. It only uses space characters as the separator of words.

^ Move the cursor to the starting position of the current row, that is, the first non-blank character position of the current row.

0 (0) Same as above

$ Move the cursor to the end of the current row, that is, the last character of the current row.

H. move the cursor to the first line at the top of the editing window.

M moves the cursor to the first position of the row in the middle of the editing window.

L move the cursor to the first position of the last row at the bottom of the editing window.

3. Insert text data

A enters text data behind the character position of the cursor.

A enters text data at the end of the row where the cursor is currently located (that is, the last character position.

I. Enter text data before the current character position of the cursor.

I input text data before the beginning of the row where the cursor is currently located (that is, before the first non-blank start character.

O input text data at the beginning of the line under the current row of the cursor.

O input text data at the beginning of the row where the cursor is currently located.

4. Modify text

C replaces all the data after the character position of the cursor in the current text line and ends with the Esc key.

Cw replaces the current character position of the cursor and the entire word or part of the word after it ends with the Esc key.

[N] cc replaces the current line, or n lines of text starting from the current line, ending with the Esc key.

[N] s replaces a single character in the current position of the cursor, or n characters starting from the current position of the cursor, ending with the Esc key.

S replaces the current row and ends with the Esc key.

R replaces a single character at the current position of the cursor.

R <Enter> disconnect rows. You can also use the "a" or "I" command to add the Enter and Esc keys.

R starts from the current character position of the cursor, replaces all subsequent characters until you Press Esc.

Xp switch character location. Switch the starting character position of the current position of the cursor.

~ Converts the case of Characters in the current position of the cursor.

U cancels the last executed edit command, or cancels the previously executed edit command in sequence.

: U is the same as above (ex edit command ).

U unedits the current text line.

5. delete text

[N] x: Delete the character at the current position of the cursor, or delete n characters starting from the current position of the cursor.

[N] X: Delete the first character of the current position of the cursor or n characters before the current position of the cursor.

Dw deletes an integral or partial character at the current position of the cursor. If the cursor is at the beginning of the word, the entire word is deleted. If the cursor is at any position in the middle of a word, the cursor position and subsequent characters are deleted.

[N] dd: Delete the text line where the cursor is currently located, or delete n text lines starting from the current row.

D. Delete All characters of the current text line starting from the cursor position.

DG deletes all text lines from the current row to the last row of the file.

D [n] G delete all text lines starting from the nth row of the file until the current row.

: Line #1, line #2 d delete all text lines from the specified line number line #1 to line #2.

6. Copy and move text

[N] yy: copy the current text line of the cursor or n text lines starting from the current line.

[N] Y.

P (lower case) paste the text line copied or deleted ("dd" command) under the row where the cursor is located.

P (uppercase) copies or deletes the text line ("dd" command) to the line where the cursor is located.

: Line #1, line #2 co line #3 set line #1 ~ Line #2 is copied to line #3.

: Line #1, line #2 m line #3 set line #1 ~ Line #2 is moved to line #3.

7. Set row number display

: Set nu adds a temporary row number during editing.

: Set nonu undo row number display (default ).

Ctrl + G display the name of the current file and the row number of the current text line.

8. Set uppercase/lowercase letter search criteria

: The case of letters is ignored when the set ic is used to retrieve strings.

: Set noic to strictly distinguish uppercase and lowercase letters when retrieving strings (default ).

9. Locate text lines

G move the cursor to the last row of the file group.

[N] G move the cursor to the nth line of the file.

10. search and replace

:/String: searches the specified string forward (end of the object.

:? String: searches the specified string backward (beginning with the object.

N finds the next matched string in the search direction.

N returns the first matched string in the reverse search direction.

: [G]/search/s // replace/[g] [c] search and replace strings.

11. Clear the screen

Ctrl + L clear the editing window that is disturbed by the output information of other processes.

12. Merge files and rows

: R filename Insert the content of the specified file after the row where the cursor is located.

: Line #1 r filename Insert the content of the specified file after line #1.

J. merge two adjacent lines of text into one line (merge the next line to the end of the current row of the cursor ).

13. Save the editing result and exit the vim editor.

: W: Save the edited result (write the data in the memory buffer to the file ).

: W! Force Save the edited result.

: Wq: Save the edited result and exit the vim editor.

: Wq! Force Save the edited result and exit the vim editor.

ZZ saves the edited result and then exits the vim editor.

: Q. You can use this command to exit the vim editor without any edits.

: Q! Force exit the vim editor and discard the edited result.

: W filename: Write the edited result to the specified file and save it.

: W! Filename forcibly writes the edited result to the specified file and saves it even if the file already exists.

: Wq! Filename forcibly writes the edited result to the specified file and saves it. Even if the file already exists, exit the vim editor.

14. Miscellaneous

F or Ctrl + G display the file name, editing status, total number of lines of the file, the row and column number of the current cursor, and the percentage of the number of lines before the current row to the total number of lines of the entire file.

Ctrl + V enter control characters.

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/PonLCan/archive/2009/10/20/4704051.aspx

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.