In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Replacement mode and visual mode of vim editor
Press r and R on the keyboard in normal mode to enter replacement mode. If you press the small r then you enter substitution mode, where the next character you type replaces the character where your cursor is currently located and automatically exits substitution mode. If you press the big R then all the characters you type below will replace the next one in turn until you press Exit Replacement Mode.
Press v and V on the keyboard in normal mode to enter visual mode. If you press the small v then you are in view mode, when you move the cursor you will select all the characters from the cursor to the end of the cursor, then you can copy, delete and so on. If you press Big V, you will also enter View mode. Moving the cursor will select all the contents from the row where the cursor is located to the end of the cursor. You can also copy and delete.
Note: Use the "ctrl+v" key combination in normal mode to enter block operation mode
In this mode and visual mode is similar, but the selection of content is different, you can actually operate to see
2. Delete characters from cursor to end of line
Enter capital "D" in normal mode or enter "d$"
3. Delete characters from cursor to start of line
Enter capital "d^" in normal mode
4. Delete the line from the cursor to the end of the file
Enter capital "dG" in normal mode
5. Delete all rows in the specified range
Example: Delete everything from lines 10 to 15
Enter ":10,15d" in normal mode Enter
6. Save the file being edited as a new file
Example: Save the file being edited as "/root/" and save it as 1.txt
Enter ": w/root/1.txt" in normal mode
Example: Save lines 10 to 15 of the file being edited as 1.txt and save it to the root directory. In normal mode, enter ":10,15 w/root/1.txt".
7. Import the contents of other files to the cursor of the file being edited
Example: Import the contents of the file "/root/1.txt" below line 10 of the file you are editing.
First press "10G" in normal mode to position the cursor on line 10
Then press "o" lowercase to start a new line below the current line and enter insert mode
Finally press on the keyboard to return to normal mode, and then type ": r/root/1.txt" Enter
8. While editing a file, you can still run linux commands without exiting the file
Column: I am editing a file, but at this time I want to see the contents of the file "/root/1.txt", but I don't want to exit the file I am editing, so we can do this
Enter ":!" in edit mode cat /root/1.txt"
9. Import the result of the command execution to the cursor of the file being edited
We can combine the above two questions and enter ":r !" in general mode. cat /root/1.txt"
10. Use of the Find Replacement function
Example: Add "#" at the beginning of lines 10 to 15
Enter ":10,15s/^/#/" in normal mode
Example: Remove the "#" at the beginning of lines 10 to 15
Enter ":10,15s/^#//" in normal mode
Example: Add "//" at the beginning of lines 10 to 15
Enter ":10, 15s/^/\/\/" or ":10,15s@^@/@" or ": 10, 15s #^#/#" in normal mode
Note: In the last of all the above commands can be added g or c together, g means that all the specified characters appearing in the line are replaced, but if g is added, then the position definition character cannot appear in front, and vice versa, then the position definition character cannot appear after g. Add c at the end to interact with the user. When the character matching the command is found, prompt the user whether to replace it. The user needs to confirm, otherwise there is no need to confirm.
11. Replace the specified character entered with the specified character
Example: When editing a document, I frequently enter a continuous string of characters such as "abcdefghijklmnopqrstuvwxyz". At this time, I want to enter only one or a string of specified characters to replace the previous characters. For example, if I specify "aming", the system will automatically replace "aming" with "abcdefghijklmnopqrstuvwxyz".
Type ":ab aming abcdefghijklmnopqrstuvwxyz" in normal mode and enter to enter edit mode. When you type "aming", you will find that it is automatically replaced by "abcdefghijklmnopqrstuvwxyz".
12. Definition of shortcut keys
Example: I want to press the ctrl+b shortcut key on the keyboard in normal mode, which will automatically insert a "#" at the beginning of the line where the cursor is located, and then automatically exit to normal mode.
Enter ":map ctrl+v ctrl+b I # " in normal mode and enter. At this time, when pressing ctrl+b on the keyboard in normal mode, the "#" sign will be inserted at the beginning of the line where the cursor is located.
Note: ctrl+v and ctrl+b in the command are the combination keys on the keyboard, not the characters entered, but the combination keys that need to be pressed, of which the first ctrl+v is pressed, and the second ctrl+b is the shortcut key to be defined. Press according to the settings you need. Then "I" means "I" in normal mode, enter insert mode and move the cursor to the beginning of the line, and then enter "#," followed by "" means exit edit mode.
13. Edit two files together or
Example: I am editing 1.txt file, and then I want to open 2.txt under root directory and edit it at the same time, and divide the window horizontally and display it together.
Type ": new/root/2.txt" in general mode
Example: I am editing 1.txt file, and then I want to open 2.txt in root directory and edit it at the same time, and divide the window vertically left and right, and display it together.
Type ": vsplit/root/2.txt" in normal mode
Note: in normal mode, press the "ctrl+w" key combination, then press the left and right, or the up and down arrow keys, you can switch between different windows. If you enter ":only" in normal mode, only the window currently being edited will be kept, and all others will be closed.
15. Case-insensitive keyword lookups in vim
Enter ":set ic" in normal mode
If you want to cancel, type ":set noise"
16. How to set the file to read-only file, save only when forced to save
Enter ":set readonly" in normal mode
17. Restore the file to its open state
Enter ":e!" in normal mode. "
18. Use of profiles
So many of the above operations, such as setting ignore case, setting shortcut keys, setting automatic replacement, and some other operations, when the computer restarts, there is no more. At this time we can write these commands to the configuration file, so that the computer can still be used after restarting, we have two ways
First: All users are unified.
Modify the "/etc/vimrc" file and add the command to be set at the end, which is the part I marked in red.
Second: only for the current user
Modify the ".vimrc" file under the user's home directory. Note that there is a point. This is a hidden file. Generally, there is no file under the user's home. You need to create it manually.
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.