Vim as your IDE Tweet

To follow this article the reader should at least have a basic idea of how to use Vim and its command modes. Or if you are new to Vim, you can read my first blog to know how I came in to Vim and its fundamental differences with other editors.

Here I'm trying to explain how to make the Vim more productive by adding some extra features through Vim plugins. After this setup the Vim would have most of the features that a modern IDE offers. I'm a python developer so this Vim setup is a little inclined to python side. But I'm including general plugins only to make it suitable for most of the programming languages.

The installation and configuration setups are being described at the end, if you want to take a look at it, go here Setup Vim from Scratch.

Update on Dec-18-2017 The plugin and vim environment got new changes. I captured it on a separate blog (https://haridas.in/vim-upgrade-2017.html). Please follow new blog entry now on. Support for vim environment specified in this blog entry is deprecated now.

The basic Vim or Vi installation comes with most of the Gnu/Linux machines are more than enough for good productive works. And Vim has plugin structure, so we can extend the Vim through plugins. The plugins further improve the productivity and reduces lot of key strokes.

The Gnu/Linux's Console or Terminal based Vim has some limitation to show good fonts and colors. So you have to install GTK version of the Vim(Gvim). Gvim gives you all the good looking features to your Vim. Just take a look at my Konsole and GTK Vim screen shots.

Vim on KDE Konsole

Gvim Here is the list of plugins that I have been configured on my Vim. It includes good color theme also. All of this Vim setup are there on my Github project. Towards the end I described how to make use of my Github project to get all of this features on your Vim. Before that first understand the functionalities and use case of different plugins and then we can go to the installation step. UPDATE (16/June/2013):- After using GVIM for a while, I came back to the Konsole itself since it's more convenient for me. But one problem with terminal is that it only support only 256 colors. But don't need to worry actually it's more than enough. On the command mode of the vim run this command to enable 256 colors - ":set t_Co=256". Actually this special setting is not required for the default themes, but if we are using new themes with more colors and font settings then those themes may not work properly on the terminal mode. So this settings will make sure that it will work even though it will degrade the features gracefully. My .vimrc has been updated with these changes so you will get it from github. Topics Plugins MinibuferExplorer. Command-t. Syntastic. Snipmate. Fugitive. NerdTree. Nerdcommenter. Rope. Tagbar. SimplePairs. Others.

Setup Vim from Scratch

Some Vim Shortcuts

Summary A Side Note In my .vimrc file, I disabled the use of arrow keys in the Vim command mode. That was forced me to learn the Vim classic hjkl arrow keys, it really worked for me. Now I don't required the key board arrow keys any more even in Vim editing mode. If you want to change this behaviour, just remove below sections from my .vimrc file. Similarly, you can just go through my .vimrc file to see other options, I tried to document my .vimrc file as much as possible. You can play around with it to make it suitable for you.

1. MinibuferExplorer (File Tabs) This is like Tabs on other IDE's. We can see the opened files on vim using this plugin. By default, we have to use :ls to see opened buffers. So this plugin makes it very convenient to view the opened files as a tabs. Vim has slightly different concept about the Tabs compared to other IDE's. Vim has support for tabs by default. That tab is different from the normal IDE's Tab. Actually the difference is that the vim tabs are a collection of opened buffers(or files.). So we can consider it as a group of tabs in other IDE context. But most of the time we only requires one vim tab and set of opened buffers(files.). The MinibuferExplorar will help you to see those opened buffers as a virtual tabs. See the screen shot below. You can use CTRL + h/j/k/l or CTRL + w to navigate around the different split windows and the mini buffer Explorer. To open a hidden buffer on a vertical split window, just go to the MinibuferExplorer and pick a file buffer(You can use normal hj keys to move horizontally on MiniBufferExplorer) then press v . Or Press s to open the buffer or file on a horizontal split window. Back to Topics

2. Command-t (File Search) Very awesome plugin for Vim. Which help us to search files very quickly. To get better speed it was implemented in C. To install this plugin you need one extra compilation of this plugin because of C code. Don't worry I explained this in the setup section. Once we have enabled this plugin you can see the search list using your <leader> + t . I'm using my leader key as , (Comma), so for me the command will looks like ,t (comma + t). Normally the leader key is "\" on your default Vim comes with your Distro. You can change this setting in .vimrc file. Actually the leader key provides a extension to use all the keys in the keyboard as your own shortcuts. This leader key is activated in the normal mode of the vim. Command-t only list all opened buffers by typing ,b in normal mode. It's very useful if we opened lot of files on your Vim. Back to Topics

3. Syntastic (Syntax Checker) Another very useful plugin for all programming languages. This plugin will help you to keep the syntax of a program correct -- like auto correct in other IDE's. This package is a general one so we can expand it very easily by support for new languages. By default it supports lot of programming languages. So this plugin is a must one for Vim. For example, if you are editing a RST file (All my blog posts are in reStructured Text format) and you made some syntax errors in it and then you saved it, after the save operation the Syntastic Plugin will check for any syntax errors on your file automatically and show you the location of the error and its reason very neatly. Take a look at a portion of the rst file of this blog post. I made a syntax error in the image tag, Similarly Synstastic will help you to follow the standard coding methods defined by different programming communities. For eg; Python code has PEP8 standard, so while writing the python code, if we are not following it, Synstastic will show you the errors. After a while you would learn the PEP8 standard without any extra work :). Back to Topics

4. Snipmate (Code Templates) A simple way to avoid typing some repetitive sequence of codes. For example, in python, we initialize a class by typing class keyword, name, etc... Instead of doing all those drama, we can just populate the default set of class structure from snipmate by typing cl <tab>. Try out it by opening a python test file. The Snimpate plugin provide a lot of such shortcuts for different programming languages. We can also define our own snippets. For web developers it would be very easy if we have snippets for <table>, <div> tag completions. By default Snipmate does have support for different html tags. Please check the snippets folder( ~/.vim/bundle/snippets/ ) to see all available snippets for a particular language or markup. More examples; vim test.py #!/bin/python cl After typing cl press tab and see the magic of full class structure. Similarly you can define your own snippets. For eg; for <tab> to expand the for statement of your language. Back to Topics

5. Fugitive (Git) This plugin is for git repository management inside Vim itself. It provides set of short commands, that we can directly use in the Vim command mode to see and do the git related operations. We don't need to go outside the editing environment to manage those stuffs. Also it have very nice git diff view inside vim itself, it is very nice to use. To see all available git commands under this plugin just type :G<tab> , Provided the current path is under git. Back to Topics

6. NerdTree (File Browser) This will display your project directory structure in tree format. It provides lot of shortcuts to navigate through the source tree easily. It is an another common Plugin required for an IDE. Check the below image to see how it looks like. Shortcuts - I mapped the following keys in .vimrc file to show and hide the Nerdtree when ever required. You can re-map this to your own choice. To open and close the Nerdtree press CTRL + n. Also you can see other available commands for this plugin by typing, ESC + :NERD <tab> Back to Topics

8. Rope Rope is a special Plugin for Python project navigation. Most of the IDE's have similar feature to see the definition of a function or class by clicking on it or via some shortcut keys. By default, if we open a Python project in Vim it won't have support for this feature. When we trying to use this feature first time, the Rope will prompt you to create a Ropeproject under current directory. And keep the configurations specific to Rope Project in ./.ropeproject folder under current directory. The Plugin helps us to create the settings easily, after that we can use this plugin to view definition of all functions or classes comes under the rope project path. In my Vim I mapped the <leader>j to :RopeGotoDefinition. For eg. import os import sys Keep your cursor on top of the os and press the <leader>j or type :RopeGotoDefinition, Vim will take you into the os file from the system path Similarly we can go to definitions of any python entity comes under the Rope path settings. You can update the Rope settings for this python project from ./.ropeproject/config.py file. This plugin also required for the modern IDE feature list. :) Back to Topics

9. Tagbar (Class Browser) This plugin is similar to the NerdTree, but instead of listing project directory structure it list the objects and functions names inside a file. Like Class browser in other IDE's. I mapped <leader>l to open tagbar and same combination to close it also. Back to Topics

10. Simple Pairs. This is a simple plugin to auto complete single quote, double quote, parentheses. This is a very handy to save few key press. Back to Topics