How to use Linux vi command

PHPz
Release: 2023-05-27 09:17:01
forward
2934 people have browsed it

1. Three modes and switching

①Command line mode ①Insert mode (enter file editing, press ESC to enter bottom line mode) ③Bottom line Mode

2. vi mode switching command

a a ---> [Enter the editing state, insert one character after the current cursor position]

A --- > [Enter the editing state, insert characters from the end of the current line]

      i     ---> [Enter the editing state, insert characters from the previous position of the current cursor]

                                                                                         -> [Enter the editing state, insert characters from the beginning of the current line]

o   ---> [Enter the editing state, insert a line, move the cursor to the beginning of the line and start inserting characters]

O ---> [Enter the editing state, add a blank line before the cursor, move the cursor to the beginning of the line and start inserting characters]

ESC ---> Enter the command state

:![ Command] Execute external Command command in vi editor [:!date] View the current time

3, paste and copy

[N]x ---> (Expurgate) Delete from N consecutive characters starting from the cursor

[N]dd ---> (delete) Delete N consecutive characters starting from the cursor and copy them to the editing buffer

[N]yy - --> (yank) Responsible for moving N lines from the cursor to the buffer

p(P) ---> (Put) Responsible for moving text from the editing buffer to the cursor

u ---> (undo) Cancel the last operation

4, save and exit

:q ---> (quit) Exit the unmodified file

:q! ---> Force exit without saving the modified parts

:w ---> (Write) Save the file without exiting

:x -- -> (Exit) Save the file and exit

:w File ---> Save as File, do not exit

:r File ---> Read the File content and insert it into Cursor position

5. [Advanced command] Cursor command

h ---> Move left

l ---> Move right

j --->Move down

k Move up

:N :N ---> Move the cursor to line N

1G ---> Move to The first line of the cursor’s file

G ---> Move to the last line

:set number ---> Set the displayed line number

:set nonumber - --> Cancel display of line number

6. [Advanced command] Search command

/string ---> Search string [n continues to search downwards, N continues to search in reverse direction , supports regular expression search: /^the】

7. [Advanced command] Replacement command

Use the :s command to implement string replacement

:s/str1/ str2/ ---> [:range s/ old/ new] Default current line

:s/str1/str2/g ---> g Replace all, without g only replace one

: .,$s/str1/str2/g ---> Replace the current line to the last line

:1,$s/str1/str2/g ---> The first line to the last line, full text

: %s/str1/str2/g ---> Full text

8. [Advanced command] is responsible for cutting commands

y0 ---> Copy the cursor to the beginning of the line, [copy part of the line]

y$ ---> Cursor to the end of the line

d0 ---> Cursor to the line Cut the first character into the clipboard

  d$  ---> Cut the character from the cursor to the end of the line into the clipboard

range y ---> Block copy, [: 119,125 y] [:,$y]

The above is the detailed content of How to use Linux vi command. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template