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 are the tips for using the Vim editor under Linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Editor to share with you what are the tips for the use of the Vim editor under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

First, back up personalized configuration files.

The Vim text editor has many default settings. But when system administrators become familiar with the tool, this default setting may not meet their needs. For this reason, system administrators want to be able to make some personalized settings like text processors such as Word, so that they can write configuration files, set environment variables, and so on. For example, the system administrator may redefine the functions of some keys, create some abbreviations, or set up a specific environment, and so on. These personalized content will be saved in a file. In the Linux operating system, this file is saved in the user's home directory by default. Usually the name of this file is vimrc. Note that this file is an invisible file. You must use the-an option to see this file. Some versions of shell may not have this file and will not be able to save personalized settings. At this point, you can copy this file from other versions of the system, which is generally generic.

This file is automatically read when the vim editor starts. Over time, this file will slowly become a dedicated library for system administrators. This file contains all the keyboard shortcuts that the system administrator is familiar with and the environment configuration that users often use. This is very important for system administrators. For this reason, the system administrator should back up this file frequently. In addition, if the system administrator often needs to move to work, also * take a copy of this file with you. In this way, even if there is a different working platform, the system administrator can easily create a familiar vim working environment by copying the file to the new platform. And this file is saved in the user's directory. For this reason, this file will not affect the vim tools of other users on this operating platform. This feature is very useful in a multi-user environment. For example, on a Linux server, database servers, mail servers, etc., are deployed at the same time, and there are different administrators to maintain them. At this point, because this configuration file is saved in their respective user directories, as long as they use different user login names, they will not interfere with each other.

Second, quickly cancel the wrong operation.

When using the vim tool in the Linux operating system, what if you enter the wrong parameter and don't know how to change the value of the previous parameter? In other text editors, such as Word text editors, undo or CTRL+z key combination can be used to undo and restore the data before modification (provided that it is not saved). But in the vim editor, you will find that this key combination does not work, and there is no undo button. Can this vim editor undo the wrong operation? In fact, there is, but the principle of its work is different from that of other editors.

When the system administrator makes an error in the process of editing the text, such as mistakenly modifying a parameter or deleting the text that should not be deleted, you can re-operate to modify the original content. However, if you do not know what was modified before, or if there are many erroneous modifications, the system administrator can press the ESC key or the U key to cancel the last operation. If this doesn't work, you can use the key combination ctrl+r to restore the last incorrect operation. Note that this ctrl+z key combination does not work in the vim editor. If you use this key combination in the vim editor, the ^ z symbol will be displayed on the terminal. It can be seen that this key combination is not defined by default in the vim editor. Note that if you are in input mode, you need to use the ESC key to exit the input mode before using the u key. Otherwise, when the system administrator uses the u key, it is treated as a normal key, that is, the u character is entered in the editor. This requires special attention and needs to exit insert mode first.

Third, pay attention to uppercase and lowercase input.

When using the vim tool to write scripts, change configuration files, and set environment variables, it is important to note that the case of the modifications is sensitive. For example, when setting environment variables, the code meaning of the uppercase path is different from that of the lowercase path. And the environment variable name itself is case-sensitive. This is different from the Windows operating system. Two environment variables, such as HOME and home, are the same environment variables in the Windows operating system. However, in the Linux operating system, it is considered to be two different environment variables because of their different case. Therefore, the author reminds system administrators that the vim editor is case-sensitive. An and A represent two different meanings and are two different commands in this tool. In vim tools, there are two main forms of conversion in uppercase. One is to press the Caps Lock key on the keyboard for case conversion. The second is to use the combination of shift key and character key to input uppercase characters. Usually, the author recommends the second method. Because when using the vi tool to set environment variables or adjust system configuration files, most files are lowercase characters. So if you use the second way, you can avoid the trouble caused by frequent case conversion, but also increase the wrong discipline. The use of shift key character combination will only convert the current character to uppercase. When you release this key, the characters you enter are still lowercase. So the chances of case errors are much lower. However, this is only suitable for cases where uppercase characters are not many. If there are more uppercase characters, then using this method will increase the workload and difficulty of typing. In other words, when you need to enter a large number of uppercase characters, you will use the * * method. That is, if you need to enter a piece of uppercase text, you can press the Caps Lock key to switch case. However, when the input is complete, you need to press the key again in time to convert the characters to lowercase. Because many vim commands are lowercase. Case-sensitive exit commands that exit the tool are case sensitive. If the system administrator enters an uppercase EXIT,vim tool, it will not be recognized and will not be able to exit the editor. Therefore, when using this Caps Lock key, you need to convert it to lowercase in time. In other words, try to use the shift key plus character combination to enter uppercase characters.

Fourth, be good at using repetition factor when entering repetitive characters.

When writing a script, you often need to write a description of the script at the beginning of the script. In order to highlight the illustrative characters of the writing, they are often surrounded by many * symbols. At this time, it will be troublesome to enter asterisks one by one. So is it possible to enter these repetitive characters quickly in the vim tool? The answer is yes. To achieve this requirement, you need to use the repetition factor. The repetition factor appears before a command and indicates the number of times a command has been repeated. Through this feature, you can quickly enter duplicate characters in the vim editing tool. The repetition factor can be used for many commands in both command mode and input mode of the vim editor. As usual, the command k means to move the cursor up one line. At this point, 10k means to move the cursor up ten lines. The Arabic numeral 10 in front of the command here indicates the repetition factor. Repetition factor can speed up the processing process and reduce repetitive input. In practical work, if we can use this repetition factor flexibly, we can often get twice the result with half the effort. While reducing the input, it can also improve the accuracy of the operation.

Vim is a very useful text editing tool in Linux operating system. Using this tool, you can complete the preparation of script files, the configuration of environment variables and other important system maintenance work. So the system administrator must be proficient in this tool. When mastering the use of its commands, we also need to master some personalized configuration and some common skills. I hope the content mentioned above can help you make better use of this vim text editing tool. It is more efficient to write scripts and modify configuration files, and the operation is more accurate and rapid.

These are all the contents of this article entitled "what are the tips for using Vim editors under Linux?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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