Vim Editor Common commands

Source: Internet
Author: User
Tags save file

Common commands
1, vi Basic concept of basically VI can be divided into three states, namely the command mode insert mode (the last line mode), the bottom row (last command mode) 1) control the movement of the screen cursor, character, Delete the word or line, move and copy a section, and enter insert mode, or go to last lines mode. 2) Insert mode is only available for text input and press the [ESC] key to return to command line mode. 3) bottom row mode (last lines) Save or exit VI, or you can set the editing environment, such as searching for strings, listing line numbers ... such as In general, however, we simplify the VI into two modes when we use it, that is, the bottom row mode (last line mode) is also counted as the command-line pattern. 2, VI Basic operation a) Enter VI in the system hint sign VI and file name, go to the VI Full screen editing screen: $ VI myfile But one thing to pay special attention to is that you enter VI, is in [command mode], you want to switch to [ Insert mode) to enter text. First Use VI people will want to use the next key to move the cursor, the result of the computer has been beep beep, the air of their own half-dead, so enter the VI, do not move, switch to [insert mode] and so on! b) switch to insert mode (insert mode) to edit the file in [command mode] Click the letter I can go into [insert modes], then you can start to enter the text. c) Insert switch you are currently in [insert mode], you can only enter text, if you find the wrong word! To move back with the cursor key, delete the word, then click the [ESC] key to go to [command mode] and delete the text. d) Exit VI and save file in command line mode save and exit: Enter ZZ under [command mode], click [:] Colon key to enter [last line mode], for example:: w filename (input [w filename] Save the article with the file name filename you specified: Wq (enter [WQ], disk and Exit VI): q! (Enter q!, do not save the force to quit VI): X (perform saving and Exit VI Editor) 3, command-line mode function key 1). Insert mode Press the switch into the insert mode, press "I" to enter the insertion mode is to start the input file from the current position of the cursor, press [a] into the insertion mode, is the current cursor position from the next position to start typing text; press [o] into insert mode, insert a new line from the beginning, enter the text. 2). Switch from Insert mode to command-line mode by pressing the [ESC] key. 3). Move the cursor vi can be directly with the cursor on the keyboard to move up and down, but the normal VI is the lowercase English letter [h], [j], [K], [l], respectively, control the cursor left, bottom, upper, and right to move one grid. Press [CTRL]+[B]: Screen to "back" to move a page. Press [CTRL]+[F]: Screen to "front" to move one page. Press [Ctrl]+[u]: Screen moves to "rear" half page. Press [CTRL]+[D]: Screen to "front" to move half a page. Press [GG]: Move to the first line of the article. (may only work in vim) press [G]: Move to the end of the article. Press [$]: moves to the end of the line where the cursor is located. Press [^]: Move to the beginning of the line where the cursor is located press [W]: The cursor jumps to the beginning of the next word by pressing [E]: The cursor jumps to the end of the next word press [b]: The cursor goes back to the beginning of the last word press [#l]: The cursor moves to the # position of the line, VI also provides three commands about the cursor moving across the screen and the file itself does not scroll. They are the H, M, and L commands, respectively. (1) The h command moves the cursor to the beginning of the first line of the screen (the upper-left corner), which is the first row of the current screen, not the first line of the entire file. Use this command to quickly move the cursor to the top of the screen. If you precede the H command with the number n, move the cursor to the beginning of the nth row. It is worth mentioning that using the command DH will remove everything from the current line of the cursor to the first line of the screen displayed. (2) The M command moves the cursor to the beginning of the middle row of the screen display file. That is, if the current screen is filled, move to the middle row of the entire screen, or, if not filled, to the middle row of those lines of text. This command allows you to quickly move the cursor from anywhere on the screen to the beginning of the middle row of the screen display file. For example, in the case where the above screen is displayed (regardless of where the cursor is on the screen), in command mode, after entering command m, the cursor will be moved to the letter a of the add line. It is also worth mentioning that using the command DM will delete everything from the current line of the cursor to the middle row of the screen display file. (3) L command when a file displays more than one screen, the command moves the cursor to the beginning of the lowest line on the screen, and moves the cursor to the beginning of the last line of the file when the file displays less than one screen. Visible, this command allows you to quickly and accurately move your cursor to the bottom of the screen or to the last line of the file. If you precede the L command with the number n, move the cursor to the beginning of the nth line from the bottom of the screen. It is also worth mentioning that using the command DLAll content from the current line of the cursor to the bottom row of the screen will be deleted. 4). Delete text [x]: Each time you press, delete the "after" character at the cursor location. [#x]: for example, [6x] means "after" 6 characters from the location where the cursor was deleted. [x]: Uppercase X, each time it is pressed, deletes the "front" character at the cursor position. [#X]: For example, [20X] means "front" 20 characters at the location where the cursor is deleted. [DD]: Delete the line where the cursor is located. [#dd]: Delete # line 5 from the line where the cursor is located). copy [yw]: Copies the character of the cursor at the end of the word into the buffer. [#yw]: Copy # Word to buffer [yy]: Copy cursor line to buffer. [#yy]: For example, [6yy] means that the copy is "down" 6 lines of text from the line where the cursor is located. [P]: Paste the characters in the buffer to the cursor location. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function. 6). Replace [R]: replaces the character at which the cursor is located. [R]: Replaces the character where the cursor is located until the [ESC] key is pressed. 7). Redo the last action [u]: If you mistakenly execute a command, you can press it and go back to the previous action immediately. Multiple replies can be performed by pressing "U" multiple times. 8). Change [CW]: Change the word at the end of the cursor [C#W]: For example, [c3w] means change 3 characters 9). Undo changes [U]: Undo the last change, you can always press [u], and always undo to the oldest modified state. [Ctrl]+[r]: Restore undo changes, you can always press the key combination to achieve the latest changes. 10). Jumps to the specified line [ctrl]+[g] lists the line number of the line where the cursor is located. [#G]: For example, [15G] means moving the cursor to the beginning of the 15th line of the article. 4. Last command in line mode before using [previous line mode], remember to press [ESC] to make sure that you are already under [command mode] and then press [:] colon to enter [end line mode]. A) List line number [set Nu]: After entering [set Nu], the line number is listed before each line in the file. B) jump to a line in the file [#]:[#] number represents a number, enter a number after the colon, and then press ENTER to jump to the line, such as enter the number 15, and then enter, will jump to the 15th line of the article. C) Find the character [/keyword]: First press the [/] key, then enter the character you want to look for, if the first keyword is not what you want, you can always press [n] will look back to the keyword you want. [? keyword]: press [?] First Key, and then enter the character you want to look for, if the first keyword is not what you want, you can always press [n] to look forward to the keyword you want. D) SaveFile [W]: Enter the letter [W] in the colon to save the file. E) Leave Vi[q]: press [Q] to exit, if you cannot leave VI, you can follow a [q] after [!] Forced to leave VI. [WQ]: generally recommended to leave, with [W] together, so that when the exit can also save the file, can be followed by the [! ] to force the save to exit. [ZZ]: Save and Exit VI.


Vim Editor Common commands

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.