In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the screen text editor Vi in linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Linux system provides a complete family of editors, such as Ed, Ex, Vi and Emacs, which can be divided into two categories according to their functions: line editors (Ed, Ex) and full-screen editors (Vi, Emacs). The row editor can only operate on one line at a time, which is very inconvenient to use. On the other hand, the full-screen editor can edit the whole screen, and the file edited by the user is displayed directly on the screen, and the result of the modification can be seen immediately, which overcomes the unintuitive operation of line editing and is convenient for users to learn and use. it has powerful functions.
Linux vi command is a full-screen interactive editing program of Linux system. It has been favored by the majority of users since its birth. After decades, it is still the main text editing tool used by people, which shows its strong vitality, and its strong vitality is brought by its powerful function.
In this chapter, we will show you step by step how to use the linux vi command to create, edit, display, and process files. (note: the uppercase letters in the text are the combination of [shift] key and corresponding lowercase letters)
Introduction to linux vi command
The linux vi command is short for "Visual interface" and has the same status on Linux as Edit programs on DOS. It can perform many text operations, such as output, delete, find, replace, block operation, and so on, and users can customize it according to their own needs, which other editing programs do not have.
The linux vi command is not a typesetting program, unlike Word or WPS, which can arrange fonts, formatting, paragraphs, and other attributes, it is just a text editor.
Linux vi commands have no menus, only commands, and there are many commands. Vi has three basic working modes: command line mode, text input mode, and last line mode.
Command line mode
At any time, no matter what mode the user is in, just press the key to make linux vi command line mode; we enter the startup linux vi command in the shell environment (prompt is $), and when we enter the editor, we are in this mode.
In this mode, users can enter a variety of legitimate linux vi commands to manage their own documents. At this time, any character entered from the keyboard is interpreted as an editing command. If the character entered is a legitimate linux vi command, the linux vi command completes the corresponding action after accepting the user's command. Note, however, that the commands entered are not displayed on the screen. If the character entered is not a legitimate command of Vi, Vi will ring the alarm.
Text input mode
Enter insert command I, add command a, open command o, modify command c, replace command r, or replace command s in command mode to enter text input mode. In this mode, any characters entered by the user are saved 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 the key.
Last row mode
The last line mode is also known as the ex escape mode.
The functions of the linux vi command and the Ex editor are the same, with the main difference being the user interface. In Vi, a command is usually a single key, such as I, a, o, and so on; in Ex, a command is a text line that ends with pressing enter. The linux vi command has a special "escape" command that accesses many line-oriented Ex commands. In command mode, the user presses the ":" key to enter the last line mode, and the linux vi command displays a ":" on the * line of the display window (usually the * line of the screen) as a prompt for the last line mode, waiting for the user to enter the 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, the linux vi command automatically returns to command mode. For example:
: 1 recordings / A / a / g
Replace all uppercase A with lowercase a from the file * * line to the end of the file.
If you change your mind while entering a command in the last line mode, you can press the key, or use the Backspace key to delete all the entered commands, and then press the backspace key to make the linux vi command return to command mode.
If you want to switch from command mode to edit mode, you can type the command 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.
Entry and exit of linux vi command
Entry of linux vi command
After the user logs in to the system, the system gives the prompt "$". Enter Vi by typing Vi and the file name you want to edit (or create) at the prompt.
[example 1] Type the command:
$vi example.c
The screen displays as follows:
~
~
~
~
~
~
~
~
~
~
~
~
~
"example.c" [New File]
If you just type Vi without a file name, you can also enter Vi. Then type the contents of the file at the cursor, and when you exit Vi, you only need to enter the file name after exiting the command.
After entering Vi, the first thing you enter is command mode, that is, waiting for command input instead of text input. At this point, all the letters entered will be interpreted as commands. The cursor hovers over the first position of the screen * * line (indicated by), and the rest of the lines have a "~" symbol at the beginning of each line, indicating that the behavior is blank. The * * line, also known as the status line, shows the name of the file currently being edited and its status. For example, this example is [New File], which means that example.c is a newly created file. If the example.c file already exists on the system, after entering the above command, the contents of the file are displayed on the screen, and the cursor stops at the first position of the * * line, and the file name, number of lines, and characters of the file are displayed on the status line.
[example 2] Type the command:
$vi example.c
Then type:
# include
Main ()
{int k
For (kryp0; k)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.