Vim is one of the most popular and powerful command line text or programming editors available on Linux. It already provides so many features that it is almost impossible for a person to learn and use each of them. But still, sometimes, you might find yourself asking for more. This is where plugins step in.
Just like Vim's long list of inbuilt features, the editor supports a lot of plugins, each aimed to help you in one particular way or the other. In this article, we will discuss three such useful plugins.
NOTE - All the plugin installation and functionality discussed in the article has been tested on Ubuntu 13.10
Before we start discussing individual plugins, lets first discuss how to install and manage Vim plugins on your Linux box. There are various plugin managers available that can be used for installation and management of Vim plugins. Here, i'll discuss plugin management using Pathogen.
Follow these steps:
- First create a directory named .vim in your system's home directory
- Inside the newly created .vim directory, create two other directories named autoload and bundle.
- Download and copy pathogen.vim to ~/.vim/autoload.
- Check if you have a ~/.vimrc file, in case you don not, create one with the same name, and add the following lines to it:
call pathogen#infect() call pathogen#helptags()
The steps mentioned above should setup the plugin manager. Now, lets discuss some plugins.
Many a times, while working with Vim, you tend to hop from one directory to another to access or open a particular file. Being command line-based, this process consumes time, especially when you are a system admin who works on command line most of the time. NerdTree is a Vim plugin that lets you easily browse the filesystem, presenting it in a tree like structure that you can easily navigate using keyboard or mouse.
Installation of NerdTree is simple. Just go to the ~/.vim/bundle directory and run git clone https://github.com/scrooloose/nerdtree.git
NOTE - If you haven't got GIT installed already, the command shown above would ask you to do that first.
Once the plugin is installed, you can enable it through :NERDTreeToggle command that lets you toggle the plugin window on and off.
To learn more about this plugin, read the NERD_tree.txt file present in the ~/.vim/bundle/nerdtree/doc directory.
This plugin is for developers. It lets you quickly hop between source and header files. For example, if you are currently writing a new function in test.c and want to declare it in test.h, the plugin lets you jump to the header file with a single command. So, you see, it makes switching between corresponding header and source files as easy as it is in a GUI-based programming IDE.
Follow these steps to install this plugin:
- Step into ~/.vim/bundle and create directories /avim, /avim/doc, /avim/plugin, and /autoload
- Download a.vim and alternate.txt
- Copy a.vim to the newly created ~/vim/bundle/autoload and ~/vim/bundle/avim/plugin directories, and alternate.txt to ~/vim/bundle/avim/doc.
- Exit vim (if already running), and start it again.
Now, the plugin is ready for use. To test it, open a source file (say test.c) in Vim editor, and run the :A command. The control should immediately switch to the corresponding header file i.e., test.h. If no corresponding file exists, the editor will open a new file by that name.
To learn more about this plugin, read ~/vim/bundle/avim/doc/alternate.txt.
If you've used bash, you must be familiar with the auto completion feature that it provides, making it easy for you to write long and complex names or paths. Supertab is a Vim plugin that adds a similar word completion ability to the command line editor.
To install this plugin, just go to the ~/.vim/bundle directory and run git clone http://github.com/ervandew/supertab.git
To use Supertab, just press Tab in Insert mode, in the places inside the opened file where you need auto-completion. A pop up menu will appear containing word completion choices.
To learn more about this plugin, read supertab.txt file present in the ~/.vim/bundle/supertab/doc/ directory.
These are just a few drops from the ocean of plugins supported by the Vim editor. Also, these plugins have a lot to offer than what we've discussed here. Go through the files mentioned at the end of each plugin section to learn more about it, and in case you have some doubt or query, leave a comment below.