Vi/vim Basic Use Method

Source: Internet
Author: User
Tags save file

This article describes the basic use of VI (VIM), but for the average user is basically enough! I/vim the difference is simple, they are multi-mode editor, the difference is that Vim is the upgrade version of VI, it is not only compatible with all VI directives, but also some new features inside. For example, with syntax highlighting, visualization can be run not only at the terminal, but also in X window, Mac OS, Windows. The VI Editor is the standard editor for all UNIX and Linux systems, and its power is not inferior to any of the latest text editors, here is simply a brief introduction to its usage and a small number of instructions. Because the VI editor is exactly the same for any version of UNIX and Linux systems, you can learn more about it in any other place where VI is introduced. VI is also the most basic text editor in Linux, after learning it, you will be in the world of Linux unimpeded. [Simply, you can use the upper and lower left and right arrows and delete,backspace keys to move and delete the position, whether it is the command mode or the insertion mode]1, VI basic concepts basically VI can be divided into three states, namely command mode, Insert mode and bottom row mode (last line mode), the function of each mode is as follows: 1) control the movement of the screen cursor, the deletion of characters, words or lines, move the copy section and enter Insert mode, Or to last line mode. 2) Insert mode is only available for text input, and press "esc" 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. However, it is important to note that after you enter VI, you are in command mode and 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 a beep, the gas to death, so enter the VI, do not move, switch to "insert mode" and then! b) switch to insert mode to editThe file can enter "Insert mode" by pressing the letter "i" under "command mode", and you can start typing. 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 then delete the text. d) Exit VI and save the file under Command mode, click the ":" colon key to enter "last line mode", for example:: w filename (enter "w filename" to save the article with the filename you specified): WQ (input "wq", disk and Exit VI): q! (Input q!, do not save the forced Exit VI) 3, command-line mode (commands) function key 1). Insert mode Press "i" switch into insert mode "insert mode", press "I" to enter the insertion mode is the beginning of the cursor from the current position of the input file, press "a" into the insertion mode, the current cursor from the location of the next position to start the input text; When o"enters insert mode, it inserts a new line and enters text from the beginning of the beginning. 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 a lowercase English letter "h", "j", "k", "l", respectively, control the cursor left, bottom, upper, and right one grid. Press "ctrl"+"b": The screen moves one page to the back. Press "ctrl"+"f": The screen moves one page to the front. Press "ctrl"+"u": The screen moves the half page toward the back. Press "ctrl"+"d": The screen moves the half page toward the front. "0" by number: Moves to the beginning of the article. 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 by "b": The cursor goes back to the beginning of the previous word by pressing "#l": the cursor moves to the first # position of the line, such as: 5l,56l. 4). Delete text "x": Each time you press, delete the "back" character at the cursor location. #x: For example, "6x" represents the "after" 6 characters of the location where the cursor was deleted. "x": Uppercase X, each time it is pressed, deletes the "front" character at the location of the cursor. "#X": for example, "20x" represents the "front" 20 characters of the location where the cursor was 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 characters from the cursor to the end of the word into the buffer. "#yw": Copy the # Word to buffer "yy": Copy the row of the cursor to the buffer. "#yy": for example, "6yy" represents a copy of 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). Reply to Last action "u": If you mistakenly execute a command, you can press "u" immediately to go back to the previous action. Multiple replies can be performed by pressing "U" multiple times. 8). Change "cw": Change the word at the end of the cursor to "c#w": For example, "c3w" means change 3 characters 9). Jumps to the specified line "ctrl"+"g" lists the line number of the row where the cursor is located. "#G": for example, "15g", which means moving the cursor to the beginning of the 15th line of the article. 4. Last command in line mode before using "last line mode", remember to press "esc" to make sure you are already under "command mode", then press ":" Colon to enter "last line mode". A) List line numbers "set nu": After you enter "set nu", the line numbers are 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 find, if the first keyword is not what you want, you can always press "n" will look forward to the keyword you want. D) Save file "w": Enter the letter "w" the colon to save the file. E) Leave vi"q": Press "q" is quit, if you cannot leave VI, can be "q" followed by a "!" Forced to leave VI. "qw": Generally recommended to leave, use with "w", so you can also save the file when exiting. 5, vi command List 1) The following table lists the functions of some keys in the command mode: H move cursor one character L move right cursor one character K cursor move up line j cursor moves down line ^ cursor to beginning 0 number "0", cursor moves to the beginning of the article G cursor moves to the end of the article Ctrl + F Front Flip Screen ctrl+b back screen ctrl+d forward half screen ctrl+u back flip half screen I at the cursorPosition before inserting character A at the beginning of the next character at the cursor position o insert a new row, enter ESC from the beginning of the line to return from the input state to the command state x delete the character after the cursor #x the # character x (uppercase X) after the cursor is deleted, delete the character in front of the cursor #x delete the # Characters DD Delete the line #dd the cursor is deleted from the line number of lines yw the copy cursor location of the word #yw the copy cursor location of the # Word YY copy cursor location of the line #yy copy from the number of lines of the cursor line P paste u cancel operation CW change the cursor location of a word # CW Change the # Character of the cursor position 2) The following table lists some instructions in the line command mode w filename stores the file being edited for FILENAMEWQ filename to store the file being edited as filename, and exits viq! discards all modifications, exits Viset Nu Display line number/or? Find, enter what to look for in/after N and/or, if the search is not the keyword you are looking for, press N or backward (with/to) or forward (with) to continue looking until you find it.



Master Summary of the figure:


Transferred from: http://www.lupaworld.com/?uid-296380-action-viewspace-itemid-118973

Vi/vim Basic Use Method

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.