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

How linux works with vi

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

Share

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

This article is about how linux uses vi to operate. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Vi (vim) is a very common editor on Linux, and many Linux distributions have vi (vim) installed by default. There are a lot of vi (vim) commands, but if you use them flexibly, you will be much more efficient. Vi is the abbreviation of "visual interface" and vim is vi IMproved (enhanced version of vi). Vi is sufficient for general system management and maintenance, and vim can be used if you want to use code highlighting. The following vps detective collates the use of vi tutorials: contains a basic introduction to vi, mode of use, file opening and closing save, insert text or new lines, move the cursor, delete, restore characters or lines, search, and so on, is a more suitable for beginners to learn vi tutorial.

Vi has three modes: insert mode, command mode, and low-line mode.

● insert mode: you can enter characters in this mode, press ESC to return to command mode.

● command mode: you can move the cursor, delete characters, etc.

● low-line mode: you can save files, exit vi, set vi, find, and other functions (low-line mode can also be seen as in command mode).

Open, save, and close files (used in vi command mode)

Vi filename / / Open the filename file

W / / Save the file

W vpser.net / / Save to vpser.net file

Q / / exit the editor, if the file has been modified, use the following command

Q! / / exit the editor without saving

: wq / / exit the editor and save the file

Insert text or line (used in vi command mode, enter insert mode after executing the following command, press ESC key to exit insert mode)

A / / add text to the right of the current cursor position

I / / add text to the left of the current cursor position

A / / add text at the end of the current line

I / / add text at the beginning of the current line (the beginning of a line that is not empty)

O / / create a new line above the current line

O / / create a new line below the current line

R / / replace (overwrite) the current cursor position and some subsequent text

J / / merge the line of the cursor and the next behavior line (still in command mode)

Move the cursor (used in vi command mode)

1. Use the up and down arrow keys

2. In command mode: h to left, j to down, k up, l to right.

The spacebar moves to the right, Backspace to the left, Enter to the beginning of the next line,-to the beginning of the previous line.

Delete or restore characters or lines (used in vi command mode)

X / Delete the current character

Nx / / Delete n characters starting from the cursor

Dd / / Delete the current line

Ndd / / Delete n lines down, including the current line

U / / undo the previous operation

U / / undo all actions on the current line

Search (used in vi command mode)

/ vpser / / search for vpser string under the cursor

? vpser / / search the cursor for the vpser string

N / / search down for the previous search action

N / / search up the previous search action

Skip to the specified line (used in vi command mode)

N + / / Jump n lines down

N-/ / Jump n lines up

NG / / Jump to the line with line number n

G / / Jump to the bottom of the file

7. Set the line number (used in vi command mode)

: set nu / / displays the line number

: set nonu / / cancel displaying line number

Copy and paste (used in vi command mode)

Yy / / copies the current line to the cache, or you can use "ayy copy," an is the buffer, or a can be replaced with any letter from a to z to complete multiple copy tasks.

Nyy / / copies the current line down n lines to the buffer, or you can use "anyy copy," an is the buffer, or a can be replaced with any letter from a to z to complete multiple copy tasks.

Yw / / copies characters from the beginning of the cursor to the end of the word.

Nyw / / copy the n words starting with the cursor.

Y ^ / / copy the content from the cursor to the beginning of the line. Detective VPS.

Y$ / / copy the contents from the cursor to the end of the line.

P / / paste the contents of the clipboard behind the cursor, if you use the previous custom buffer, it is recommended to use "ap" to paste.

P / / paste the contents of the clipboard in front of the cursor, if you use the previous custom buffer, it is recommended to use "aP" to paste.

9. Replace (used in vi command mode)

: s/old/new / / replace the old that first appears in the line with new

: s/old/new/g / / replace all old in the line with new

: n s/old/new/g m s/old/new/g / / replace all old from n to m lines with new

:% s/old/new/g / / replace all old in the current file with new

10. Edit other documents

: e otherfilename / / Edit the file named otherfilename.

11. Modify the file format

: set fileformat=unix / / modify the file to unix format, for example, the text file under win will appear ^ M under linux.

Conclusion: although the vi (vim) tutorial has more commands, as long as you practice frequently, I believe you will quickly master it, and at the same time, it will bring more efficiency to your work or study. If you don't know what mode you are in, you can press ESC twice to return to command mode. There will be one final reminder: pay attention to case!

1. About quitting

: wq!-force save exit

Wq-Save exit

X-has the same effect as wq.

ZZ-works the same as: wq, (note that Z is uppercase and not in command mode)

: Q-quit

: Q!-compulsory exit

=

two。 About Mobility

H: move one character to the left on the current line

J: move to the next line

K: move to the previous line

L: move one character to the right on the current line

Ctrl + f: scroll forward one page

Ctrl + b: scroll back one page

: n position the cursor to the nth line

: $position the cursor to the last line

0 position the cursor at the beginning of the line

Position the cursor at the end of the line

G position the cursor to the last line of this article, which is the same as: $.

H position the cursor at the top of the screen

M positions the cursor in the middle of the screen

L position the cursor at the bottom of the screen

=

3. About search

/: followed by what you are looking for, search forward in the file

?: followed by what you are looking for, search backward in the file

N: repeat the search forward

N: repeat the search backwards

=

4. About replication

Yy: copy cursor current line

Nyy: copy the current line of the cursor to the nmur1 line below the current line

: 1100 co 200copies the contents of 1x100 to line 200.

: 100102 co $copies the contents of 100,102 lines to the last line.

=

5. About pasting

P: paste to the next line of the current line

P (large): paste to the previous line of the current line

=

6. About deletion. Shear

Dd deletes the current line

Ndd is similar to nyy

Dw deletes a word

Ndw is similar to ndd

X Delete a character

Nx deletes n characters

DG deletes everything from the current cursor to the end of the file.

D0 deletes everything from the current cursor to the beginning of the line

D $removes everything from the current cursor to the end of the line

1100d delete 1100

100d delete line 100th

: 1100 mo $moves the contents of one hundred lines to the last line.

=

7. About inserting

I: enter insert mode before the character in the current position

I: insert at the beginning of the current line

A: enter insert mode after the character in the current position

A: insert at the end of the current line

O: open a new row below the current line to insert

O: open a new row above the current line to insert

=

8. About revocation

U: undo the last change

=

9. About replacement

Regexp: is the style to match

Replacement: is the string to replace

: s/regexp/replacement-replaces the first style that appears in the current line

: s/regexp/replacement/g-replaces all matches on the current line

:% s/regexp/replacement/g-replace all matching styles in the file

=

PS: another important order is "." Command, this command is used to repeat the previous command

How about in vi: undo the last operation? Repeat a set of editing operations multiple times? .

A) undo the last edit operation. = > u

B) repeat the previous edit operation. = >.

C) restore the undone editing operation. = > Ctrl + R

D) repeat a set of editing operations multiple times. The command repeats the last editing action.

"Brother Bird's Linux private dish" vi handout picture is relatively large and automatically zoomed in. It is recommended to download it and open it for viewing.

Thank you for reading! This is the end of this article on "how to operate linux with vi". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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

Wechat

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

12
Report