Vi and vim commands in Linux

Source: Internet
Author: User
Vi is a widely used text editor in unix/linux. vi has various variants and different variant software on different machines. among them, vim is relatively easy to use and widely used. vim is short for ViIMproved, indicating better vi. this article describes some of the useful features,
I. general mode: the commands for deleting, copying, and pasting x and X are used to delete one character backward. x is the first character to delete nx (n indicates a number) delete n characters backward dd delete the current row D delete all characters in the current row and try to become a blank row ndd (n indicates a number) delete the row where the cursor is located in the n-down column d1G delete all data from the row where the cursor is located to the first row dG delete all data from the row where the cursor is located to the last row yy copy the row where the cursor is located y1G copy the row where the cursor is located to all data in one row yG copies all data from the row where the cursor is located to the last row ynj (n indicates a number) copy the row where the cursor is located to n + 1 rows down dnj (n represents a number) delete the row where the cursor is located to n + 1 rows down p, P p is the copied data pasted in the next row of the cursor, p: copy the data and paste it on the top of the cursor. a line J combines the row where the cursor is located with the data of the next row into a line u to restore the previous action (undo). 2. edit mode command I, I is to insert the input text at the current cursor position, I is to insert the input text a in the first non-empty character in the row where the cursor is located, A a inserts the input text next character at the cursor's position, and A inserts the input text at the next character of the last character in the row where the cursor is located. o, O o inserts characters at the beginning of the next line in the row where the cursor is located, O inserts characters at the beginning of the previous line in the row where the cursor is located r, R r is the character that replaces the cursor, R is the character that always replaces the text pointed by the cursor until exit Esc, return to Normal Mode 3. command mode h. move a character j. move a character k. move the cursor up a character l. move a character Ctrl + f. turn a page down Ctrl + screen B flip one page up Ctrl + screen d flip half page down Ctrl + u screen flip half page up + move the cursor to the first non-empty character in the next line-move the cursor to the first character in the current line non-null characters, n spaces (n stands for numbers) the cursor moves n characters 0 (number 0) to the right of the current row and the cursor moves to the first character of the current row (can be null characters, note and-distinguish) $ move the cursor to the last character of the current row (it can be a null character, note and-distinguish) H move the cursor to the first non-empty character M in the row at the top of the current screen move the cursor to the first non-empty character in the middle of the current screen L move the cursor to the bottom of the current screen move the cursor of the first non-empty character G in a row to the first non-empty character nG in the last line of the article (n indicates a number) move the cursor to the first non-null character n in the n row of the article
 Move the cursor from the current row down to the first non-null character of n rows/word search for the word string after the cursor? Word searches for the word string s/word1/word2/g before the cursor, searches for word1 in the current row, and replaces it with word2: n1, n2s/word1/word2/g searches for word1 between line n1 and line n2 and replaces it with word2: % s/word1/word2/g to search for word1 in the entire article, replace it with word2: w to save the edited data to the hard disk file: w [filename] to save the edited data to another file on the hard disk: r [filename] reads data from another file when editing the data, and adds the content in the filename file to the row where the cursor is located. the row wq or: x is saved and the row q exits, applies to unmodified files: q! Force exit: Applies to modifying files without saving exit: set nu displays row number: set nonu cancels row number: n1, n2 w [filename] saves the content from n1 to n2 to a file named filename.
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.