Vim text editor under the Linux command line

Source: Internet
Author: User
Tags save file


Vim text editor under the Linux command line


Vim text Editor is a very powerful tool that can do many things, such as creating new files, opening files, editing files, saving files, and opening multiple files at the same time. Here is a summary of some of the commonly used VIM editor commands:


1.The way to enter the VIM editor: (When entering the VIM editor, the default mode is "Command mode") in the terminal input VI: Enter the VIM editor VI filename: Enter the VIM editor, create a new filename file, the cursor navigates to the first line of the file vi at work, The. SWP temporary file is created in the current directory, which is also known as the swap file when VI ends the edit of the current file and exits gracefully when the temporary file. SWP will be automatically deleted when VI finishes editing the current file and exits abnormally, temporary files. SWP will be left behind. VI + FileName: Enter the VIM editor, open the existing filename file, and the cursor navigates to the last line of the file vi at work, A temporary file named. FILENAME.SWP is created in the same directory as the edited file. When VI finishes editing the current file and exits gracefully, the temporary file is deleted. FILENAME.SWP will be automatically removed when VI finishes editing the current file and exits abnormally, temporary files. FILENAME.SWP will remain. Down VI +# FileName: Enter the VIM editor, open the existing filename file, and position the cursor to line # (#必须用数字代替) of the file vi-r filename: Enter the VIM editor to open the existing filename file as read-only, The edited file cannot be stored back, but can be saved as Vi-r filename: Recover files from VI crash or non-normal exit vi-r. *.SWP: Recover files from the interchange file. *.SWP: Lists all the swap files in the current directory that are remaining due to the non-normal exit of VI. In order to recover vi-l: Lists all the swap files in the current directory that are remaining due to the non-normal exit of VI in order to recover 2.VI has three ways of working: Command modeedit ModeAnd Command Entry modeCommand mode:In this mode, the contents of the file can be processed (copy, delete, move, etc.) by entering VI's command, or you can move the cursor by pressing the cursor key. edit mode:In this mode, you can enter content at the cursor. Command entry mode:In command mode, after the user enters a colon, the cursor jumps to the bottom line and then enters the command. Command mode--input A, a, I, I, O, O and other commands--edit mode edit mode--Press ESC---Command mode


Command mode--input colon-to-command item mode


3.Exit VI command in command mode, enter: W Save the file, do not exit vi:w filename to save the contents of VI to the nonexistent filename file, do not exit vi:w! FileName Saves the contents of VI to the existing filename file, does not exit Vi:w>>filename appends the contents of VI to the filename file, does not exit vi:n1,n2w filename Save the contents of the N1 line to N2 to the nonexistent filename file: n1,n2w! FileName Saves the contents of N1 line to N2 to the existing filename file: Wq save file, exit Vi:x save file, exit Vi:zz save file, exit Vi:q do not save file, Exit VI (cannot exit if file has changed): q! Do not save file, Exit VI


: ZQ do not save file, Exit VI


4.In command mode, you can enter the following command: (1) Cursor movement command h: Left L: Right K: Upper J: Left cursor key right cursor key up cursor key down cursor key


(2) Insert command


I: inserting content at cursor I: inserting content in the first row a: inserting content after the cursor 

a: Inserting a new line at the end of the current line o: Insert a new row below the current line O Delete command 

x: Delete the character at the cursor x: Delete a character before the cursor D0: Deletes a string of characters from the first character of the current cursor to the previous character of the current cursor 

D: Deletes a string of characters from the current cursor's character to the last character of the current cursor's line DD: Delete all characters from the cursor at the same line A word for example: a boy girl pig if the cursor is in L, after DW, the result is: A boy girpig if the cursor is in the space between L and P, after DW, the result is: A boy girlpig if the cursor is at B, after the DW, the result is: a girl pig# DD: Delete the #-1 line (#Must be replaced by numbers) from the line where the cursor is located 

#x: Delete the # characters (#必须用数字代替) from the character where the cursor is located (the "#"): n1,n2 D: Delete the contents of the N1 line to the N2 row

 (4) Copy command: N1,N2 t N3: Copy the contents of the N1 line to the N2 line to the next line of the N3 row (5) Move command: n1,n2 m N3: Move the contents of the N1 line to the N2 row to the next line of the N3 row 

(6) Modify/replace command r: Enter a character at the cursor to replace the character R: start with the character at the cursor, The character that follows is an input character that overrides s: Enter a string to replace the character s at the cursor: first clear the line where the cursor is located, you can enter a string of characters in the current line cc: First clear the line where the cursor is, you can enter a string of characters in the current line CW: Modify a word for example: AB cdef Ghijk cursor at D, after the input CW, the result is: AB cde$ Ghijk, at this time if the input pqghd, the result is: AB CPQGHD Ghijk at this time if the input p after pressing ESC, the result is: AB CP GHIJKC: Modify the section at the beginning of the cursor and after that line for example: AB cdef Ghijk cursor at D, after input CW, the result is: AB Cdef ghij$, at this time after the input pqghd, the result is: AB CPQGHD (7) Cursor Position Command 0: Navigate to the beginning of the line where the cursor is located $: Navigate to the end of the line where the cursor is located: #: Navigates to the beginning of the # line: $: Navigates to the beginning of the last line/exp: Navigates backward to string Exp?exp: Navigates forward to string Exp/^exp: Navigates to line with string exp at beginning of row/ exp$: Navigate to the line at the end of the line n,m?/exp: Search strings from n lines to M lines exp (this command is debatable) n,m |/exp: Search strings from n rows to M for string exp (This commandOpen for discussion) (8) Search Replace command: s/exp1/exp2/g: Replace the string exp1 of the current line with a string exp2:n,m s/exp1/exp2/g: Replace the string exp1 of n rows to m rows with a string exp2:g/exp1/exp2/ G: Replace string exp1 of the current line with string exp2:g/exp1/s//exp2/g: Replace string exp1 in full text with string EXP2 (9) Undo command U (10) buffer command By default, VI uses the nameless buffer, For example, although some parts of the file have been deleted, you can still use the U name to undo it. YY: Place the line where the cursor is in the nameless buffer y: Place the line where the cursor is located in the nameless buffer p: Pastes the contents of the buffer into the next line of the cursor's row p: Pastes the contents of the buffer into the row where the cursor is located "#yy: Place the line where the cursor is in the buffer # (#必须用a ~z instead) P: Paste the contents of the buffer # into the next line of the row where the cursor is located (#必须用a ~z instead) "#P: Paste the contents of the buffer # into the row of the cursor (#必须用a ~z instead)" #d: Delete the current row and put the contents of the current row into the buffer # (11) Other commands: Set Nu: Display line number: Set Nonu: Cancel line number: N navigates to the next file: N navigates to the previous file VI 1.c 2.c 3.c: Open 3 files at a time first will open 1.c, enter: N command, will open 2.c, and then enter: N command, will open 3.c, and then enter: N Command, will open 2.c, and then enter: N command, will open 1.c. Ctrl+g: Displays information about the currently edited file Ctrl+l: Refresh the screen ctrl+d: Turn back half screen ctrl+u: Turn back half screen ctrl+f: Turn backward one screen ctrl+b: turn one screen forward


Vim text editor under the Linux command line


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.