Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Common knowledge of vi command

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Vi + file

Example: vi 1.txt

Common modes of vi commands (command mode, bottom line mode, edit mode)

What is the relationship between command mode, bottom line mode and edit mode?

Vi--  command mode-insert--  editing mode-esc  command mode-shift+ (:)  bottom line mode

Tips for using the vi command:

The skill of moving the cursor quickly

G/shift+g-quickly switch the cursor to the last line

Gg-quickly switch the cursor to the beginning of the file line

10gg-switches the cursor to the specified line

$- quickly switch the cursor to the end of a line

0 / ^-quickly switch the cursor to the beginning of a line

Quickly move the cursor and enter the editing state:

O-place the cursor on a new line below the current line and enter the editing state

O-place the cursor on a new line over the current line and enter the editing state

I-enter the editing state directly at the current position of the cursor

I-switch the cursor to the beginning of a line and enter the editing state

A-switch the cursor to the end of a line and enter the editing state

A-the next character in the current position of the cursor enters the editing state.

C-clear all the content to the right of the cursor and enter the editing state

Cc-clear the entire line and enter the editing state

Quickly edit file content information

Yy-copy the specified content information

Nyy-copy multiple lines of information

P-paste copied or cut information

3p-paste the copied or cut content 3 times

Dd-delete (cut) specify a line of information

Ndd-delete (cut) specify multiple lines of information

DG-delete everything after the line of the cursor (cut)

R-replace the character information where the specified cursor is located

R-enter into replacement mode, you can replace multiple character information

Bottom line function instruction

: set nu-displays file line number information

: set nonu-cancels the display of file line number information

: s/oldboy/oldgirl/-replace the information about the location of the cursor

:% s/oldboy/oldgirl/-replace all specified contents in the file

: 7recover12sUniverse /-replaces the specified line information

: 6 replacements: Oldboyax /-replace the specified line to the last line of the specified content

: 6 the match found in the line is replaced by all the information retrieved in the line.

: 6. Replace the first matching information retrieved in a row.

Note: when the replacement instruction is used, the split symbol can be used with / / # # @

/ searched information-retrieve and filter specified information in the file

N means to retrieve the next matching information

N means to return to the previous matching information

/ searched information\ c-ignore case when retrieving information in files

Special operation skills

U-- undo-undo operation in vi editing

Ctrl+r-- redo-cancel the undo operation in vi editing

Common misoperations of vi command

E325: ATTENTION

Found a swap file by the name ".1.txt.swp"

Owned by: root dated: Thu Sep 5 19:15:04 2019

File name: / 1.txt

Modified: YES

User name: root host name: oldboyedu.com

Process ID: 7820

While opening file "1.txt"

Dated: Thu Sep 5 19:14:47 2019

(1) Another program may be editing the same file. If this is the case

Be careful not to end up with two different instances of the same

File when making changes. Quit, or continue with caution.

(1)。 Another file that may be edited is the same. if so, be careful not to change, exit or continue when two different stories are the same, remind you

(2) An edit session for this file crashed.

If this is the case, use ": recover" or "vim-r 1.txt"

To recover the changes (see ": help recovery").

If you did this already, delete the swap file ".1.txt.swp"

To avoid this message.

(2)。 A modified file, if this is the case, overwrite the change with "recover" or "vim-r 1.txt" (see help "recovery"). If you have done the previous operation, delete the swap file "1.txt.swp" to avoid this message

Swap file ".1.txt.swp" a

```lready exists!

[O] pen Read-Only, (E) dit anyway, (R) ecover, (D) elete it, (Q) uit, (A) bort:

The cause of the problem:

(1)。 Two people edit a file at the same time

(2)。 This file was modified, but it was not saved properly to exit, resulting in a swp file

Solution:

(1)。 Multiple people turn off editing files

(2)。 Use the vim-r 1.txt file, restore and save the file, and delete the swp file data if it is already normal

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report