Under Linux, vi editing mode basic operation command

Here patients to / etc / passwd top ten acts

First, vi is the Linux terminal or console conventional editor, the basic mode of operation is:
vi / path / filename

Here Insert Picture Description
after entering the press "a", "i", "o" keys can edit the file

Method exits vi editing mode:
Press the "esc" key, enter ": q!" To force quit (Note that the "colon" is a must), "q!" Was forced to withdraw (without saving the current editor) input ":! wq" to save and exit (same here, "colon" is a must).
Or: Insert key is pressed, the window can see the left-bottom "Insert" word representing the current editing state to be inserted, this time from the contents of the keyboard input is inserted at the cursor position; Insert key is pressed again, the lower left corner of the " replace "word representing the current state of editing Alternatively, this time from the contents of the keyboard input replace the contents of the cursor position.

Shortcut keys:

First press "esc" to enter the command mode

  1. "Yy" Copy the current cursor line, "3yy" Copy the current cursor row and two rows located below the row;

  2. "P" to paste the copied content to the row below the cursor;

  3. "Dd" to delete the cursor line content, "3dd" delete the current cursor line and the following two lines;
    Here Insert Picture Description
    Here Insert Picture Description

  4. "U" to return to previous operation ( "withdraw")
    Here Insert Picture Description
    Here Insert Picture Description

  5. "G" cursor to the last row;

  6. "Gg" cursor to the first line;

  7. "DG" Delete cursor line to the end of the file;

Find the shortcut file contents

: Press the "esc" key, enter ": \ field to find what you want". The cursor will move to the first file in the contents of the location you entered, then press the "N" key, to be Find the same field contents, pressing the "n" key will look up the same. (Note: Here "colon" and "" are a must!).

Replace the contents of the shortcut file

Syntax: s/xx/xxReplace cursor line content you want to replace (the first "xx" input field contents you want to replace the second "xx" Enter what you want to replace the contents of the field).
Example: Here Insert Picture Description
we must enter ": s / root / mark"
Here Insert Picture Description
So if you want to "root" the entire line are replaced by "mark", then: You can enter ": s / root / mark / g" ( where " g "can be understood as" global "global (whole line))
Here Insert Picture Description
expansion: ①," s "can be replaced with"% s "representative of full replacement ("% s / root / mark " the full text of the" root "replace" mark ");
②," may be replaced by S "3,5s" ( "3,5s / root / mark" the "root" of the third row and the fifth row replaced by "Mark");
③, "also S can be replaced ". 3, $S" ( ". 3, $S / the root / Mark" the third row to the last row of the "root" replace "mark").

Extended command mode

Enter ": set nu" display text line numbers.
Enter ": set list" to display the full text of blank lines.

Summary: The above is the basic operation vi mode, do not know if there is the little sister of the micro-channel can be added: 1,430,016,196.

Released two original articles · won praise 2 · views 98

Guess you like

Origin blog.csdn.net/liu1430016196/article/details/104711003