Use vim basic commands

Source: Internet
Author: User
Basic usage of vim commands using vi/vim 1. basic concepts of vi there are basically three states: command mode and Insertmode) compared with lastlinemode, Each mode has the following functions: 1) Command Line... basic usage of vim commands using vi/vim 1. basic concepts of vi there are basically three states: command mode and Insert mode) compared with the last line mode, each mode has the following functions: 1) command line mode: controls the movement of the screen cursor, the deletion of characters, words, or lines, move and copy a certain segment and enter the Insert mode, or to the last line mode. 2) the Insert mode can be used for text input only in the Insert mode. press the ESC key to return to the command line mode. 3) the last line mode saves or exits the file vi. you can also set the editing environment, such as searching strings, listing row numbers, and so on ....... However, we generally simplify vi into two modes in use, that is, the last line mode is also included in the command line mode ). 2. basic operations on vi a) after entering the vi and file name in the system prompt symbol, go to the full-screen vi editing screen: $ vi myfile, but pay special attention to it, after you enter vi, it is in "command mode". you must switch to "Insert mode" to enter text. People who use vi for the first time will want to move the cursor first with the upper and lower right keys. as a result, the computer keeps beeping and getting angry with themselves. so after entering vi, do not tamper with the mouse, switch to "Insert mode! B) switch to Insert mode. click "I" under "command mode" to enter "Insert mode) ", then you can start entering text. C. Insert switch: you are currently in "Insert mode", and you can only enter text all the time. if you find that you have entered an error! To move the word back with the light Mark key, you must first press ESC to switch to command mode and then delete the text. D) exit vi and save the file. in command mode, click ":" colon to enter "Last line mode". for example :: w filename (enter "w filename" to save the article with the specified filename): wq (enter "wq", save the disk and exit vi): q! (Enter q !, Do not save disk force exit vi) 3. command line mode function key 1 ). in insert mode, press I to switch to insert mode. in insert mode, press I to enter insert mode. then, the file is input starting from the current position of the cursor; after you press "a" to enter the insert mode, the text is input starting from the next position where the cursor is currently located. after you press "o" to enter the insert mode, a new row is inserted, enter text from the beginning of the line. 2) switch from Insert mode to command line mode and press ESC. 3 ). move the cursor vi can move up, down, and left directly with the cursor on the keyboard, but the regular vi uses lowercase letters "h", "j", "k", and "l 」, the cursor is controlled to move one cell to the left, down, up, and right respectively. Press ctrl + B to move the screen to the back. Press ctrl + f to move the screen to the front. Press ctrl + u to move the screen to the back half of the page. Press ctrl + d to move the screen half to the front. Press the number "0": to move to the beginning of the article. Press G to move to the end of the article. Press "$" to move to the end of the row where the cursor is located ". Press "^": move to the "first line" of the row where the cursor is located press "w": the cursor jumps to the beginning of the next word and press "e 」: move the cursor to the end of the next word and press "B": the cursor returns to the beginning of the previous word and press "# l": the cursor moves to the # position of the row, for example, 5l, 56l. 4). delete the text "x": each time you press it, delete the "next" character of the cursor location. "# X": for example, "6x" indicates deleting the "next" 6 characters of the cursor position. "X": uppercase X. each time you press it, the "front" character of the cursor is deleted. "# X": for example, "20X" indicates the position where the cursor is located, which is a string of 20 characters. Dd: delete the row where the cursor is located. "# Dd": delete from the row where the cursor is located # row 5). Copy "yw": Copy the character from the cursor to the end of the character to the buffer zone. "# Yw": Copy # words to the buffer zone "yy": Copy the row where the cursor is located to the buffer zone. "# Yy": for example, "6yy" indicates copying 6 lines of text from the row where the cursor is located "down. P: place the characters in the buffer to the cursor position. Note: all copy commands related to "y" must work with "p" to complete the copy and paste function. 6) Replace "r": replace the character at which the cursor is located. "R": replace the character wherever the cursor goes until you press the "ESC" key. 7). reply to the previous operation "u": if you mistakenly execute a command, you can immediately press "u" and return to the previous operation. You can perform multiple replies based on multiple "u" requests. 8 ). change cw: change the word at the cursor to c # w at the end of the word. for example, c3w indicates changing 3 Words 9 ). jump to the specified row ctrl + g to list the row number of the cursor. "# G": for example, "15G" indicates moving the cursor to the first row of the article. 4. before using "Last line mode", remember to press the "ESC" key to confirm that you are already in "command mode", and then press 「: "Colon to enter" last line mode 」. A) list the row number "set nu": after entering "set nu", the row number is listed before each row in the file. B) jump to a line in the file "#": "#" indicates a number, enter a number after the colon, and press the Enter key to jump to this line. for example, enter the number 15, press enter to jump to the second line of the article. C) search for the character "/keyword": First press the "/" key, and then enter the character you want to search. if the first search keyword is not what you want, you can always Press "n" until you find the keyword you want. 「? Keyword: First press 「?」 Enter the character you want to search for. if the keyword you want for the first time is not what you want, you can press "n" until you find the keyword you want. D) save the file "w": Enter the letter "w" on the colon to save the file. E) exit vi "q": Press "q" to exit vi. if you cannot leave vi, you can follow "q" 「!」 Force exit vi. "Qw": it is generally recommended to use it with "w" when leaving, so that files can be saved when exiting. 5. vi command list 1. the following table lists some key functions in command mode: h move cursor to the left one character l move cursor to the right one character k move cursor up one line j move cursor down one line ^ move cursor to the first line 0 number "0 ", move the cursor to the beginning of the article G move the cursor to the end of the article $ move the cursor to the end of the line Ctrl + f forward screen Ctrl + B backward screen Ctrl + d forward half screen Ctrl + u back flip half screen I insert character a before the cursor position the next character at the cursor position begins to add o insert a new line, start from the beginning of the line and enter ESC from the input state to the command state x delete the character after the cursor # x delete the # character after the cursor X (uppercase X ), delete character before cursor # X Delete character before cursor # Character dd delete row where cursor is located # row yw copy a word at cursor position # yw copy the cursor position # word yy copy the line where the cursor is located # yy copy the line from the number of lines where the cursor is located # Line p paste u cancel Operation cw change a word where the cursor is located # cw # Words for changing the cursor position 2. some commands in the following table Travel command mode w filename store the file being edited as filename wq filename store the file being edited as filename and exit vi q! Discard all modifications and exit vi set nu to display the row number/or? Search, enter the content n and/or? If the search content is not the keyword, press n or backward (and/) or forward (and? Continue searching until it is found.
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.