In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the skills of using linux vi editor", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "what are the skills of using linux vi editor"!
I. Introduction to Linux vi editor
Linux vi editor is the unix world's most common full-screen editor, linux is used in the enhanced version of vi vim,vim is fully compatible with vi, vi is the abbreviation of "visual interface". It can perform output, delete, find, replace, block operations and many other text operations, and users can customize it according to their own needs, which is not available in other editing programs.
vi is not a typesetting program, it is not like Word or WPS can be font, formatting, paragraphs and other attributes of the layout, it is just a text editing program.
There is no menu, only commands, and many commands. Just type vi on the command line to access vi's editing environment. vi has three states: command mode, text input mode and last line mode. Enter vi and enter to enter vi command mode first.
In command mode, any character input by the user is interpreted and executed by Vi as a command. If the user wants to regard the input character as text content, he should first switch the operation mode of Vi from command mode to text input mode. In command mode, press the "a"("A") key or the "i"("I") or "o"("O") key to enter the inserted text input mode. Press "a" key to insert behind the current cursor; press "i" key to insert at the current cursor; press "A" key to insert at the *** of the line where the current cursor is located; press "I" key to insert at the beginning of the line where the current cursor is located. In text input mode, press Esc to return to command mode.
Last row mode is also known as ex escape mode. Vi has a special "escape" command that provides access to many line-oriented Ex commands. In the command mode, the user presses the ":" key to enter the last line mode. At this time, Vi will display a ":" in the ** line of the display window (usually the ** line of the screen) as the prompt of the last line mode, waiting for the user to input the command. Most file management commands are executed in this mode (e.g., writing the contents of an edit buffer to a file). After the last command is executed, Vi automatically returns to command mode.
For example:
:1,$s /A/a/g
Replace all capital A's with lowercase a's from file *** to the end of the file.
If you want to switch to command mode during command input in last line mode, press the key, or use the backspace key to delete all the input commands, and then press the backspace key to return Vi to command mode.
To switch from command mode to edit mode, type a or i; to return from text mode, press Esc. Enter ":" in command mode to switch to last line mode and enter the command.
Many of the commands in Vi require numerical values such as line numbers and rows. If the edited file is large, it is very inconvenient to count it yourself. For this Vi provides the ability to add line numbers to text. These row numbers appear on the left side of the screen, and the contents of the corresponding row appear after the row number. It should be noted that the line numbers added here are only displayed to the user and are not part of the file content.
When creating a new file with Vi, the file name may not be given in the command to enter Vi. When the file needs to be saved after editing, the user specifies the file name.
When entering Vi, the user can specify not only a file name to edit, but also many additional operations. If you want the cursor to be on a particular line in the file after entering Vi, you can add an optional +n to Vi, where n is the specified number of lines. For example, after typing the command: vi +3 example.txt, the cursor will be located on line 3 in the file example.txt.
II.VI Frequently Used Orders
1. Insert command
Vi provides two insert commands: the i and I commands
(1)i command
Inserting text starts before the cursor position, and you can use the key to delete incorrect input during insertion. Vi is inserted and the words "--INSERT--" appear at the bottom of the screen.
Example 1: There is a file being edited, as follows:
Welcome to vi world! Come on!
~
~
The cursor is located at ***"! "above, insert before it:
This is an example!
After using the i command and entering the appropriate text, the screen displays the following:
Welcome to vi world This is an example!! Come on!
~
~
As you can see from this example, the cursor was originally in ***"! ", but since it is inserted from before the cursor position, this"! "is squeezed behind the newly inserted text.
(2)I command
This command moves the cursor to the beginning of the current line and inserts text before it.
2. Cursor movement moves on screen
Cursor movement is undoubtedly the most frequently used operation in the full-screen text VI editor. Only by skillfully using these commands of moving the cursor can the user quickly and accurately reach the desired position for editing.
Cursor movement in Vi can be done in either command mode or text input mode, but the method of operation is different.
(1)In text entry mode, you can move the cursor directly using the four arrow keys on the keyboard.
(2)In command mode, there are many ways to move the cursor. Not only can you use the four direction keys to move the cursor, but you can also use the four keys h, j, k, l instead of the four direction keys to move the cursor, so that you can avoid conflicts caused by different keyboard definitions on different machines, and you can complete all operations without leaving the letter keyboard position after using it skillfully, thus improving work efficiency.
3. move across the screen
The Vi editor provides three commands for cursor movement across the full screen without scrolling the file itself. These are H, M and L commands.
(1)H command
This command moves the cursor to the top of the first line of the screen (i.e., the upper left corner), which is the *** line of the current screen, rather than the *** line of the entire file. Use this command to quickly move the cursor to the top of the screen. If the H command is preceded by the number n, move the cursor to the beginning of line n. It is worth mentioning that using the command dH will delete everything from the current position of the cursor to the first line of the displayed screen.
(2)M command
This command moves the cursor to the beginning of the middle line of the on-screen file. That is, if the current screen is full, move to the middle lines of the entire screen; if not, move to the middle lines of those lines of text. Use this command to quickly move the cursor from any position on the screen to the beginning of the middle line of the on-screen display file. For example, in the case of the above screen display (regardless of where the cursor is on the screen), after entering the command M in command mode, the cursor will move to the letter a in the add line. It is also worth mentioning that using the command dM will delete everything from the current line of the cursor to the middle line of the file displayed on the screen.
(3)L command
This command moves the cursor to the beginning of the *** line on the screen when the file is displayed on more than one screen, or to the beginning of the *** line when the file is displayed on less than one screen. Visible, using this command can quickly and accurately move the cursor to the bottom of the screen or file ** line. If the number n precedes the L command, move the cursor to the beginning of the nth line from the bottom of the screen. It is also worth mentioning that using the command dL will delete everything from the current line of the cursor to the bottom line of the screen.
4. editing commands
Let's look at the simplest and most common editing process: no one is infallible. So sooner or later you're going to have to change the text you type. In fact, most of the time spent on word processing is modifying rather than typing new things. Therefore, it is important that you know how to modify it easily.
(1)x--delete a character
The easiest way to delete text is to use x. The result of this command is that the cursor character disappears and the text behind it moves to the left. If the character you delete is one character in a line ***, the cursor will move one to the left so that it doesn't stay under the nonexistent character. If there are no more words, the horn goes off.
(2)d--delete object
There must also be some text object on the right side of this command. A text object is a piece of text. To his right are the characters that control cursor movement. For example w represents one word forward, dw deletes the next word. 5w means forward 5 words, then d5w will delete them.
(3)dd--delete a line
One of the most commonly used d series commands. As before, 5dd will delete 5 lines
(4)D-Delete the whole
A capital D is used to delete from the cursor to the end of the line. Same effect as d$.
(5)u--recovery
Regret? He doesn't just undo deletions, he undoes all your editing.
(6).-- repeated
Repeat editing.
5. Exit Vi Editor
When you're done editing a file and ready to exit Vi and return to shell, you can do one of several things.
(1)In command mode, double press capital letter Z, if the current edited file has been modified, Vi saves the file and exits, returning to shell; if the current edited file has not been modified, Vi directly exits, returning to shell.
(2)In last line mode, enter the command:w Vi to save the current edit file, but do not exit, but continue to wait for the user to enter the command. When using w command, you can give the edit file a new file name.
Example:w newfile
At this point Vi will save the contents of the current file to the specified newfile, while the original file remains unchanged. If newfile is an existing file, Vi will prompt you in the status line of the display window:
File exists (use ! to override)
At this point, if the user really wants to replace the original contents of newfile with the current contents of the file, you can use the command
:w! newfile
Otherwise, choose another filename to save the current file.
(3)In last line mode, enter the command:q system exit Vi to return to shell. If the edited file is not saved when exiting Vi with this command, Vi displays the following message at the bottom line of the display window:
No write since last change (use ! to overrides)
Prompt the user that the file has not been saved after modification, and then Vi does not quit, continue to wait for user commands. If the user does not want to save the modified file and wants to forcibly exit Vi, use the command:q! Vi abandons the changes and goes directly to the shell.
(4)In last line mode, typing the command:wq Vi will save the file and then exit Vi to return to shell.
(5)In last line mode, enter the command:x. This command has the same function as the ZZ command in command mode.
At this point, I believe that everyone has a deeper understanding of "what are the skills of using linux vi editor", so you may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.