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

What is the file editing command of Linux system?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Linux system editing file command is what, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

First, the vi editor has three basic working modes. First of all, you need to know that the vi editor has three basic working modes, namely: command mode, text input mode, and last line mode.

First: command line mode: this mode is the default mode after entering the vi editor. Any time, no matter what mode the user is in, press the ESC key to enter the command mode. In this mode, users can enter vi commands and manage their own documents. At this point, any characters entered from the keyboard are interpreted as editing commands. If the character entered is a legitimate vi command, vi completes the corresponding action after accepting the user's command. It is important to note, however, that the commands entered are not echoed on the screen. If the character entered is not a vi command, vi will ring the alarm.

Second: text input mode: enter command I in command mode, add command a, open command o, modify command c, replace command r or replace command s can enter text input mode. In this mode, any characters entered by the user are protected by vi as the contents of the file and displayed on the screen. During text entry, if you want to return to command mode, press ESC.

Third: the last line mode: the last line mode is also called ex escape mode. In command mode, the user presses the ":" key to enter the last line mode, where vi displays a ":" on the last line of the display window (usually the last line of the screen) as a specifier for the last line mode, waiting for the user to enter a command. Most file management commands are executed in this mode (such as writing the contents of the edit buffer to a file). After the last-line command is executed, vi automatically returns to command mode. If you want to switch from command mode to edit mode, you can type an or I. If you need to return from text mode, press ESC. Enter ":" in command mode to switch to the last line mode, and then enter the command.

To sum up, when we use a command to open a file, we enter the command mode. In the command mode, you can switch to the text input mode and the last line mode, but the text input mode and the last line mode cannot be switched directly to each other, so the text input mode can be switched to the last line mode, you need to return to the command mode and then switch, and vice versa.

In addition, editing text can be edited in text input mode, keyboard input can edit the text, or using vi command in command mode can also play an editing effect.

Second: example demonstration: first of all, we use the command vi filename to open a file, this time we enter the command mode, then we press I, and then enter the write content casually on the keyboard. Then press ESC to return to command mode. In the case of command mode, we press: to enter the last line mode. We type wqstores, then enter, and forcibly save and exit. The next time we open the corresponding file (which can be opened with the less filename command), we can see that the content has changed.

Add: (1) in the last line mode: Q! [force exit do not save] Q [exit do not save] wq [exit and save can also be added after! ] (2) if you do not want to save direct exit, you can use the "ctrl+z" shortcut key or hold down the "shift" key in command mode, enter two z to exit.

More commands into vi commands vi filename: open or create a file and place the cursor at the beginning of the first line vi + n filename: open the file and place the cursor at the beginning of line n vi + filename: open the file and place the cursor at the beginning of the last line vi + / pattern filename: open the file and place the cursor at the first string that matches pattern vi-r filename: system crash occurred the last time you were editing with vi, restore filenamevi filename... .filename: open multiple files and edit them in turn

Screen tumble command Ctrl+u: turn half the screen to the beginning of the file Ctrl+d: turn half the screen to the end of the file Ctrl+f: turn a screen to the end of the file Ctrl+b; turn a screen to the first screen nz: scroll the nth line to the top of the screen and scroll the current line to the top of the screen when n is not specified.

Insert text class command I: before the cursor I: at the beginning of the current line a: after the cursor A: at the end of the current line o: below the current line O: open a new line above the current line r: replace the current character R: replace the current character and subsequent characters until press the ESC key s: from the current cursor position, replace the specified number of characters with the text entered S: delete the specified number of lines And replace the ncw or nCW with the entered text: modify a specified number of words nCC: modify a specified number of lines

Delete command ndw or ndW: delete the word do at the beginning and after the cursor do: delete to the beginning of the line: delete to the end of the line ndd: delete the current line and after the line 1 line x or X: delete a character, x delete the character after the cursor, and X delete the Ctrl+u before the cursor: delete the text entered in input mode

Search and replace command / pattern: search the end of the file from the beginning of the cursor pattern?pattern: search the first of the file from the beginning of the cursor patternn: repeat the previous search command N: repeat the previous search command in the opposite direction: s/p1/p2/g: replace all p1 in the current line with p2: N1 N2s/p1/p2/g: replace all p1 with p2 in lines N1 to N2: g/p1/s//p2/g: replace all p1 with p2 in the file

Option setting all: list all options setting case term: set terminal type ignorance: ignore case list: display tab stop (Ctrl+I) and line end flag ($) number: display line number report: display number modified by line-oriented commands terse: display short warning message warn: display NO write information if the current file is not saved when going to another file nomagic: allowed in search mode Use the special character nowrapscan without "\" before: prohibit vi from starting from the other end when the search reaches both ends of the file. Mesg: allow vi to display information written by other users to their terminals with write.

Last line mode command: N1 co N2: copy the contents between lines N1 to N2 under line n3: N1 min3: move the contents between lines N1 to N2 to line N1: N1 N2 d: delete the contents between lines N1 and N2: W: save the current file: e filename: open the file filename for editing: X: save the current file and exit: Q: exit the file: do not save the file and exit the shell command: execute the shell command: command:n1,n2 the contents of lines N1 to N2 in the file as input to command and execute it If N1 command N2 is not specified, the entire file content is used as the input to the command: ringing command: put the output of the command command on the current line

Register operation? nyy: saves the contents of the current line and its next n lines to a register, where? is a letter and n is a number? nyw: saves the current line and its next n words to a register? In, among them? For a letter, n is a number "? nyl: saves the current line and its next n characters to a register, where? is a letter and n is a number"? P: take out the register? And place it at the cursor position. Here? It can be a letter or a numeric ndd: delete the current line and its total n lines of text, and put the deleted contents in the No. 1 delete register.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Development

Wechat

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

12
Report