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

How to use the utility plug-in of vim

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

It is believed that many inexperienced people are at a loss about how to use the utility plug-in of vim. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Vim is a common text editor under Linux, but it is often referred to as an ancient artifact because it is quite unfriendly for beginners and difficult to get started.

However, for experts, they not only play Vim very well, but also use it as the main tool for code development. Why? Because IDE such as VS is relatively large and slow to run, while Vim is quite lightweight, it can instantly open the code and start working, which is naturally admired by experts in the pursuit of efficiency.

However, if it is the official version of Vim, it is still quite limited and very inconvenient. But a master is a master after all, and a master knows how to use plug-ins.

1. Automatic completion of parentheses plug-in

This plug-in is called Auto Pairs, and it can automatically complete matching symbols, such as curly braces, square brackets, parentheses, quotation marks, etc. This is very useful for us programmers, because we use a lot of the above matching symbols in the code, and if we can complete it automatically, it will greatly improve our efficiency in writing bug.

After using this plug-in, when we type in a symbol, it will automatically complete another symbol that it matches. For example, when we type in, it will be completed automatically. When we delete [,] is automatically deleted.

If we turn on automatic indentation, it not only completes the matching symbol in the right place, but also inserts the cursor in the right place. For example, the following Go code:

Package mainimport "fmt" func main () {x: = true items: = [] string {"tv", "pc", "tablet"} if x {for _, I: = range items}} now, I insert a curly bracket {after the penultimate line items, and then hit enter We get the following result: package mainimport "fmt" func main () {x: = true items: = [] string {"tv", "pc", "tablet"} if x {for _, I: = range items {| (the cursor is here)}

Of course, Auto Pairs also offers a lot of options, and we can see more usage in its Github repository. However, the above basic usage can already save us a lot of time.

2. Code block comment plug-in

As a qualified ancient artifact, Vim has no way to annotate code blocks like those IDE. But with the plug-in NERD Commenter, we can achieve this goal.

NERD Commenter is smart enough to automatically recognize the code and give the annotation style of the corresponding language. In the easiest way, we can quickly comment on the block of code by typing + spaces in command mode. Here, the key defaults to the backslash key, and we can also customize it.

How do we select multiple rows? That is to be done in visual mode (Visualization Mode), which is the basic operation of Vim.

Another useful feature is Sexy Comment (sexy mode), which can be triggered using + cs. Sexy mode can annotate code blocks in an elegant way, such as the following style comment is sexy mode:

Package mainimport "fmt" func main () {/ * * x: = true * items: = [] string {"tv", "pc", "tablet"} * * if x {* for _, I: = range items {* fmt.Println (I) *} * * /}

3. Add a surround symbol plug-in

The Vim Surround plug-in is a killer because it can add existing code as a pair of enclosing symbols. For example, we now have a line of code:

"Vim plugins are awesome!" If we want to remove the quotation marks, just type ds ": Vim plugins are awesome! if we want to change the double quotation marks to single quotation marks, we can type cs": 'Vim plugins are awesome!' It's the same thing if you want to change to other symbols. Not only that, it also supports HTML or XML markup language very well. For example, there is such a HTML sentence: Vim plugins are awesome! Now that we want to bold the word awesome, we can place the cursor over the word and type ysiw, and it automatically adds a tag: Vim plugins are awesome! Vim Surround can also add a bounding symbol at the top and bottom of the statement in a jagged manner, and automatically indent the current statement. For example, if we want to tag the above code, we can click ySS:Vim plugins are awesome! Similarly, its features are not only that, we can go to its Github repository to see more powerful features.

The above three Vim plug-ins will save us a lot of time if they are used skillfully, and they are also very easy to use, which can improve our efficiency.

After reading the above, have you mastered how to use the utility plug-in of vim? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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