Ah, Vim. Love it or hate it, many developers swear by this powerful, console-based text editor, while others used it once and never want to use it again. Vim has been around since 1991 and shows no signs of fading. I’m even writing this article in Vim.
If you’ve used Vim before, you know there’s a bit of a learning curve. It takes patience to learn how to control Vim with key commands when you’re used to using graphical text editors. I’m still acclimating, but I love Vim more every day.
One of Vim’s features is extreme extensibility. If you can dream it up, there’s probably a plugin for it. Today I’m going to introduce 8 useful plugins that will help you be more productive when using Vim. If you lean towards hating it now, give these plugins a try and then see how you feel.
Pathogen is a package manager for Vim plugins, and it should be the first plugin you install. By default, Vim places all of its plugin files in the same directory. This can get messy when you have a lot of plugins that consist of more than one file, and you might have trouble identifying the appropriate files when you want to remove a plugin. Pathogen solves this problem by placing each plugin in its own directory within “~/.vim/bundle”.
To install Pathogen, grab the file pathogen.vim from here and place it in the directory “~/.vim/autoload” (create that directory first if it doesn’t already exist). Also create the directory “~/.vim/bundle”. Then add these lines to your ~/.vimrc file:
call pathogen#infect() call pathogen#helptags() syntax on filetype plugin indent on
Restart Vim to effect the changes. Now every plugin that you place in a subdirectory of “~/.vim/bundle” will be automatically installed.
NERDTree is a tree-style file browser for Vim.
To use NERDTree, execute
:NERDTreeClose to exit it. Press “?” to view a list of key commands.
The developer recommends installing it via Pathogen like so:
cd ~/.vim/bundle git clone https://github.com/scrooloose/nerdtree.git
Now generate the reference manual for NERDTree by running this command within Vim (note: press the “esc” key to get to the command prompt):
You can now use the command
:help NERD_tree to view the help documentation at any time. Generating a manual in this fashion is standard practice when installing Vim plugins.
Are you a huge fan of bash-style tab completion like I am? Check out SuperTab. It displays a menu of possible word completions when you type the tab key after a non-blank character.
SuperTab just completed the word “SuperTab” for me when I typed “S” + [TAB]. Cool, huh?
The easiest way to install SuperTab is to grab the file supertab.vmb (which is an archive called a “vimball”) and place it into your “~/.vim/bundle” directory. Then open it in Vim and source the file:
vim supertab.vmb :so %
That’s all there is to it. Of course, as with most Vim plugins, there are about a bazillion ways you can customize SuperTab. See the documentation on GitHub for details.
Surround is a plugin that gives you shortcuts to deal with punctuation and tags that surround text.
For example, let’s say you have the string:
"I love plugins!"
Navigate to somewhere inside the quotation marks and hit the key sequence
cs"' to change the double quotations to single quotations, making it:
'I love plugins!'
To delete both delimiters, hit
ds". That’s just scratching the surface of this powerful utility; visit the GitHub page for more information.
To install Surround, use Pathogen as usual:
cd ~/.vim/bundle git clone git://github.com/tpope/vim-surround.git
Vim-Dict is a handy word lookup tool that uses the dict protocol to connect to online dictionaries.
To enable all the available dictionary databases at dict.org, you could put this in your ~/.vimrc:
let g:dict_hosts = [ \["dict.org", ["all"]] \]
The problem with doing that is that there are a lot of dictionaries (you can see the full list by entering
:DictShowDb), and enabling them all makes the search function sluggish. Alternatively, you might just choose a few to enable, including the Free On-Line Dictionary of Computing (FOLDOC):
let g:dict_hosts = [ \["dict.org", ["gcide", "wn", "moby-thes", "vera", "jargon", "foldoc", "bouvier", "devil"]] \]
:Dict [word] to use the dictionary.
cd ~/.vim/bundle git clone https://github.com/szw/vim-dict.git
I’m a Tomboy Notes power-user, but when I’m working in Vim, it gets frustrating to have to keep switching out of my terminal window to manage my notes. Enter the Notes plugin for Vim.
Taking notes with Notes is simple and elegant. To get started with a new note, just type
:Note. Notes supports simple markup with tags such as
DONE and underscores and asterisks for italics and bold, respectively. It also includes embedded syntax highlighting for code.
cd ~/.vim/bundle git clone https://github.com/xolox/vim-notes.git
7 & 8. Screen and Vimux
If you use the terminal a lot, you might already be familiar with the screen-splitting tools GNU Screen and Tmux (I happen to love Tmux). These plugins are Screen and Tmux implementations that run inside Vim.
Install the application Screen, then run:
cd ~/.vim/bundle git clone https://github.com/ervandew/screen.git
Install Tmux, then run:
cd ~/.vim/bundle git clone https://github.com/benmills/vimux.git
If these useful plugins have whetted your appetite for terminal productivity, go browse the official Vim scripts repository for more. Happy nerding!
Our latest tutorials delivered straight to your inbox