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

Linux vi/vim common commands (important! )

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

Share

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

You can use the vi/vim command if you want to open it or create a new one and edit it from the command line window. First of all, the vi/vim:vi editor is the standard editor for all Unix and Linux systems. It is equivalent to notepad in windows systems, and its power is not inferior to that of any latest text editor. It is an indispensable tool for us to use Linux system. Since the vi editor is exactly the same for any version of Unix and Linux systems, after learning it, you will walk freely in the world of Linux.

Vim has the ability of program editing, and can distinguish the correctness of syntax by font color, which is convenient for program design.

Because the program is simple, the editing speed is quite fast.

Vim will judge the content of the file according to the file extension or the beginning information in the file, and automatically execute the syntax judgment of the program, and then display the program code and general information in color.

Many additional features have been added to vim, such as regular expression search, multi-file editing, block copying, and so on.

General mode:

Opening a file in vi goes directly to normal mode (which is the default mode). In this mode, you can use the up and down keys to move the cursor, you can use delete characters or delete the entire line to process the contents of the file, or you can use copy and paste to process your file data.

Edit mode:

Delete, copy, paste, etc., can be done in normal mode, but the contents of the file cannot be edited. Only when you press any letter [I, I, o, O, a, A, r, R] will you enter edit mode. At this point, the words [INSERT or REPLACE] appear in the lower left of the screen, and you can edit it at this time. If you want to return to normal mode, you must press [Esc] to exit editing mode.

Command line mode:

Enter any of the three to move the cursor to the bottom line. In this mode, the actions that can be provided to find, read, save, replace characters, leave vi, display line numbers, and so on are done in this mode!

Usage: vi text name. Extensions such as vi hello.txt enter hello.txt file general mode, and edit mode only when you press any of the letters [I, I, o, O, a, A, r, R]. Then introduce the functions of these keys.

[I, I] enter edit mode:

I is [insert from the current cursor]

I is [start inserting at the first non-space character on the current line]

[a, A] enter edit mode (Insert mode):

An is [insert from the last character on the line where the cursor is located]

[o, O] enter edit mode:

O is [insert a new line at the next line where the current cursor is located]

O inserts a new line for the previous line at the current cursor

[r, R] enter substitution mode:

R will only replace the character where the cursor is located once.

R replaces the text where the cursor is located until ESC is pressed

Press [Esc] to exit editing mode and return to normal mode

Buttons available for switching from general mode to command line mode

[: W] Save edited content

[: W!] force writing to the file, but it is related to your permissions on the file

[: Q] leave vi without modification

[: Q!] do not want to save changes and force to leave

[: wq] force write and save and leave

[: X] leave after saving

[: N1 filename N2 w] saves the contents of N1 to N2 as a filename file.

[:! Command] temporarily leave vi to display the result of executing command in command line mode! For example, [:!

[: set nu] displays the line number

[: set nonu] as opposed to set nu, it cancels the line

The buttons available in general mode describe

Move the cursor

[h, j, k, l], control the cursor to move one grid to the left, down, up and right, respectively

Press the [ctrl+b] screen to move one page back.

Press the [ctrl+f] screen to move one page forward

[Home] move to the first character of this line: 0 number, but cannot use the number on the numeric keypad

[End] move to the last character of this line: $, I can't test it.

[e] the cursor jumps to the suffix of the next word

[h] the cursor moves to the first character of the top line of the screen

[M] the cursor moves to the first character of the middle line of this screen

[l] the cursor moves to the first character of the bottom line of the screen

[G] move to the last line of this file

[gg] move to the first line of the file, which is equivalent to 1G

[n] move the cursor down n lines

Find and replace

[/ word] look down the cursor for a string named word

N1 and N2 are numbers, look for the string word1 between lines N1 and N2, and replace the string with word2

Find the word1 string from the first line to the last line and replace it with word2

Find the word1 string from the first line to the last line, and replace the string with word2, and prompt the user to confirm whether to replace it before replacing

Delete, copy, and paste

[X] deletes one character backward (equivalent to the [del] key)

[X] to delete one character forward (equivalent to [backspace] key)

[nx] delete n characters back in succession

[dd] Delete the line of the cursor

[ndd] Delete the downward n line where the cursor is located

[D1G] Delete all data from the row of the cursor to the first row

[dG] Delete all data from the cursor to the last row

[d $] Delete the cursor to the last character of the line

[D0] Delete the cursor to the first character of the line

[yy] copy the line where the cursor is located

[Y1G] copy all data from the line of the cursor to the first row

[yG] copy all data from the line where the cursor is located to the last row

[P] paste the copied data on the next line of the cursor

[P] is the line above the cursor

[U] resume the previous operation

[Ctrl+r] redo the previous operation

[.] is to repeat the previous operation

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