How to use the VI editor in Linux

Source: Internet
Author: User
Tags save file

Experiment one: The VI editor mode switch 1.       Experimental goal: Master VI editor Three modes of switching and its characteristics 2. Experimental procedure: Step one: Enter the VI editor, which is the command mode Enter VI or VIM in the command terminal by going to VI editorStep two: Switch to the last line mode step three: Switch to input mode 3. Experiment Summary:switching from the input mode to the last line mode must first switch to command mode, which is toggled by pressing the "ESC" key, while the command mode and the remaining two modes can be switched arbitrarily. Experiment Two: Command 1 with Command mode. Experimental objective: To have a clear understanding of commands in command mode and to use them skillfully. 2. Experimental procedure: Step one: Save and exit the file⑴, non-modified exit ⑵, save and exit⑶, do not save exitStep two: Cursor movement and page flipping⑴, cursor movement⑵, page flippingStep three: In-line quick jump⑴, "^" Jump: The cursor quickly jump to the line of the line character;⑵, "$" Jump: Quickly jump the cursor to the line end of the bank character;⑶, "W" Jump: Quickly jump the cursor to the position of the current cursor at the beginning of the first letter of a word;⑷, "E" Jump: Quickly jump the cursor to the position of the current cursor at the end of the last word of the letter;⑸, "B" jump: Quickly jump the cursor to the position of the current cursor at the beginning of the first letter of a word;Step four: Enter input mode⑴, "I": Enter the insertion state at the current cursor;⑵, "s": delete the character at the current cursor and enter the insertion state; ⑶, "a": Enter the insertion state after the current cursor;⑷, "A": Moves the cursor to the end of the current line and enters the insertion state;⑸, "O": Insert a new line below the current line, the cursor moves to the beginning of the new line, into the insertion State;⑹, "O": Insert a new line above the current line, the cursor moves to the beginning of the new line, into the insertion State;⑺, "C": Delete the current cursor to the end of the word at the end of the character, and into the insertion State;Step five: Quick jump between documents and insiders⑴, "1G": Jump to the first line of the file;  ⑵, "G": Jump to the end of the file line;  Step Six: Delete operations⑴, "x": Deletes a single character at the cursor;⑵, "dd": Delete the line where the cursor is located;⑶, "DW": Removes all characters from the current character to the end of the word (including spaces); ⑷, "de": Removes all characters from the current character to the end of the word (excluding spaces at the tail of the word);⑸, "J": Deletes the line break at the end of the line at which the cursor is located, equivalent to merging the contents of the current row and the next line;Step Seven: Undo action⑴, "U": cancels the most recent operation and restores the results of the operation multiple steps can be resumed using the U command;⑵, "U": Cancels all operations on the current line;⑶, "ctrl+r": Recovery of operations that use the U command to undo;Step eight: Copy and paste operations⑴, "yy": Copy the contents of the entire row of the current line to the vi buffer;⑵, "yw": Copy the contents of the current cursor to the end of the word to the vi buffer;⑶, "P": reads the contents of the vi buffer and pastes it to the current position of the cursor (without overwriting the contents of the file);3. Experiment Summary:² in command mode, the "^" command is used in combination with other commands, "^" indicates forward, "$" indicates backwards. ²In command mode, when you use the Delete command and the Copy command, you can precede the command with a number that represents the number of rows to be deleted or copied. Experiment three: Use command 1 in the last line mode. Experimental objective: To have a clear understanding of the commands in the last-line mode and to use them skillfully. 2. Experimental procedure: Step one: New, open and read and save files⑴, open a new file: i. Open the new file to the VI Editor:
: E filename
II.Open the new file to the VI editor and discard the changes to the current file:
: e! FileName
⑵, read the contents of the file into the current VI editor:
: R filename
⑶, save file: Save changes to the open file in VI Editor;
: W
⑷, Save as File: Save the contents of the VI editor as the specified file name;
: W myfile
Step two: Display and cancel line numbers in the editor⑸, displaying line numbers in the editor:⑹, cancels the display of line numbers in the editor:Step three: Exit VI Editor⑴, unmodified exit: No changes are made to the file opened in the VI editor, or modified and saved, exit the VI editor directly;
: Q
⑵, Save and exit: Save the file in the VI Editor and exit the VI editor;
: QW
⑶, do not save exit: Discard changes to the contents of the file, and exit the VI editor;
: q!
Step Four: String lookup operations
Command Function
/word Look up the string "word" from the top down in the file
? word Bottom find the string "word" in the file
N Locate the next matching found string
N Locate the previous matching found string
Step Five: String substitution operation
Command Function
: s/old/new Replace the first character "old" string found in the current line with "new"
: s/old/new/g Replace all the string "old" found in the current row with "new"
: #, #s/old/new/g Replace all strings "old" with "new" in the line number "#,#" range
:%s/old/new/g Replace all strings "old" with "new" for the entire file range
: s/old/new/c Adding the C command at the end of the Replace command will prompt the user for each substitution action to confirm
Step Six: VI Multi-file Operations Command 
commands features
: args < strong> Display Multi-file information
: Next switch files back
:p Rev Toggle file forward
: First /td> locating the first file
: Last locating tail file
Ctrl + ^ quickly switch to the file before switching in the editor
3. Experiment Summary:²The VI Editor can open multiple text files at the same time for editing²only one file is displayed in the edit area of the VI editor, and other open files are placed in the background²the contents of the editing area in VI can be toggled between multiple open files²VI when you switch from one file to another, you should save the changes or discard the changes firstExperiment four: Use command 1 in input mode. Experimental objective: To have a clear understanding of the commands in the input mode and to use them skillfully. 2. Experimental procedure: Step one: Edit key operation of input mode
Keys Function
Direction key Move the cursor around the upper and lower left direction
Home Quick position cursor to beginning of line
End Quick position cursor to end of line
PageUp To page up the text
PageDown To page down the text
Backspace Delete the character to the left of the cursor
Del Delete the character at the cursor position
3. Experiment Summary:the Edit key action method in VI is the same as in Windows.

This article is from the "God Only" blog, please be sure to keep this source http://shenzhi.blog.51cto.com/1012057/225355

How to use the VI editor in Linux

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.