Vim is a popular text editor for Linux, but it is often called an archaic artifact because it is rather unfriendly and hard to get started with for beginners.

But for the pros, Vim is not only a great tool to play with, but also a major tool for code development. Why is that? While IDES such as VS are bulky and slow to run, Vim is lightweight and can open up code and start working in a flash, which is a great treat for productivity geeks.

However, if it is the official version of Vim, it is still quite limited and very inconvenient. But a master is a master, and a master knows how to use plug-ins. The following good xu on the introduction of master commonly used 3 very practical plug-ins.

1. Parenthesis auto-completion plug-in

This plugin is called Auto Pairs and it can automatically complete Pairs of symbols such as braces, square brackets, parentheses, quotes, etc. This is very useful for us programmers, because we use a lot of these pair symbols in our code, and it would greatly improve our bug writing efficiency if we could auto-complete them.

With this plugin, when we type in a symbol, it will automatically complete its matching symbol. For example, when we type [it will auto-complete]. When we delete [,] is automatically deleted.

If we turn autoindent on, it will not only complete the matching symbol in the right place, but also insert the cursor in the right place. For example, here’s the Go code:

package main

import "fmt"

func main() {
    x := true
    items := []string{"tv", "pc", "tablet"}

    if x { 
        for _, i := range items
    } 
}Copy the code

Now I insert a curly brace {after items on line 3 from last, and hit Enter, and we get something like this:

package main import "fmt" func main() { x := true items := []string{"tv", "pc", "tablet"} if x { for _, I: = range items {| (cursor here)}}}Copy the code

Of course, Auto Pairs also provides many options, and you can see more usage in its Github repository. However, these basic uses can save us a lot of time already.

2. Code block annotation plug-in

As an ancient artifact, Vim can’t comment code blocks like those ides can. But with NERD Commenter, we can do just that.

NERD Commenter is smart enough to automatically identify code and comment style for the language. In the simplest way, we can quickly comment out blocks of code in command mode by typing

+ space. In this case, the default key is the backslash \ key, which we can also customize.

How do we pick multiple rows? That is to do in Visual Mode, this is the basic operation of Vim.

Another useful feature is Sexy Comment, which can be triggered using

+ CS. Sexy mode allows code blocks to be commented in an elegant way, such as the following style of comment:

package main

import "fmt"

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

3. Add a bounding symbol plug-in

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

"Vim plugins are awesome !"Copy the code

If we want to get rid of the quotes, just hit ds” :

Vim plugins are awesome !Copy the code

If we want to change double quotes to single quotes, we can type cs”‘ :

'Vim plugins are awesome ! 'Copy the code

It’s the same thing if you want to switch to other symbols. Not only that, it supports HTML or XML markup languages very well. For example, here’s an HTML statement:

<p>Vim plugins are awesome ! </p>Copy the code

Now that we want to bold the word awesome, we can place the cursor over the word and type ysiw and it will automatically add the mark:

<p>Vim plugins are <em>awesome</em> ! </p>Copy the code

Vim Surround can also use a zigzag approach to Surround the top and bottom of a statement and indent the current statement automatically. For example, if we wanted to add a tag to the code above, we could type ySS

:
<div class="normal"> <p>Vim plugins are <em>awesome</em> ! </p> </div>Copy the code

Again, it does more than that, and you can check out its Github repository for more powerful features.

summary

The above three Vim plug-ins will save us a lot of time if we skillfully use them, and they are also very handy to use, which can improve our efficiency. Of course, there are many useful plugins developed by great people in the Vim community, and there will be some more fun plugins in the future, so stay tuned!

Finally, recently, many friends asked me for Linux learning roadmap, so I stayed up for a month in my spare time according to my own experience, and sorted out an e-book. Whether you are interviewing or self-improvement, I believe will help you! The directory is as follows:

Free to everyone, just ask everyone to point to me!

Link: pan.baidu.com/s/1_6uniaFV… Extraction code: 9pBC

Also hope to have a small partner can join me, do this e-book more perfect!

Have a harvest? Hope the old iron people come to a triple whammy, give more people to see this article

Recommended reading:

  • Dry goods | programmers advanced architect necessary resources free of charge
  • Artifact | support resource site search