If you are asking why I would want to write about a boring topic again, then this post of obviously not for you. This post is for anyone who's interested in using the mighty and great Vim editor and it's variations (Eg: vim, gvim, etc.) properly.
What has changed?
I had pushed my Vim configuration to a GitHub repo named gavim and had been using it for a while. And couple of people even forked the repo. Despite how proud I was about my editor configuration, ;) there were some obvious problems.
First, a few things were broken (Eg: proper snippet usage) and some plugins weren't working any-more (Eg: Fuzzy_Finder_Textmate) and I wasn't using some of the plugins and wanted to used some other plugins.
More than anything maintaining a Vim configuration was messy because you had to copy all the files from all the plugins into one hairy ball of a directory. I never liked that. Along came Tim Pope with Pathogen which changed how people can manage Vim configs.
So I sat down, threw away most of my old configuration files and started anew; Gavim2
Gavim2 (since renamed to Gavim, again)
Let's start with my .vimrc file. As usual I had copied over some default configuration stuff from Fedora's default system-wide vim configuration file. And started adding my preferences.
The option 'nocompatible' tells Vim that it doesn't have to try to be "exactly" like its father; the venerable vi. This is a must have if you are to enjoy the niceties Vim has. So instead of trying to be completely 'vi' compatible we can exploit additional features of 'vim'.
The 'bs' (settings for backspace) options allows me to backspace over a few things I like. For example "eol" will name vim allow me to use backspace to get to the previous line (above the line termination). The next two lines asked vim to keep a '.viminfo' file and to limit the command line history to 50 entries respectively.
The 'number' option tells vim to show line numbering.
'incsearch' allows to search incrementally while typing in the search pattern. This way I don't have to wait till I enter the full pattern to see results. 'modelines' value is set to "0" because I've read somewhere that it can be exploited as a security vulnerability. Although I can't remember exactly how it is done, I set the value to 0 because I'm not using modelines.
While 'ignorecase' disables the case-sensitivity in search patterns, 'smartcase' requires "ignorecase" and overrides it if the pattern contains any uppercase characters.
I've set the F2 key to toggle the "paste" option by setting it as the value for 'pastetoggle'. This is really useful if you want to copy something into what you are editing and temporarily turn-off auto-indentation.
Edit: I've also made vim use 2 spaces instead of a tab character. This is set with the options 'tabstop' (number of spaces for tab), 'shiftwidth' (number of spaces for an autoindent step), 'softtabstop' (number of spaces for tab when editing) and 'expandtab' (expand tabs into spaces). By using all 4 of these options I've made sure that what I write isn't messed up when viewed elsewhere.
I've also used used 'mouse' option to enable mouse use in plain vim. This makes the select with mouse behave more like gvim (Eg: do not select line numbers). For word and code completions sake I've also set 'ofu=syntaxcomplete#Complete'. Among other goodies, I've configured a keybinding (i.e.:
The following things are explained in the comments.
Plugins & Bundles
What I've done with plugins is managing them with Tim Pope's pathogen plugin with the use of Git submodules.
As you might have already figured out my while Vim configuration is a Git repository, which makes managing things far easier and better. Since the use of pathogen makes plugins easier to manage separately and as bundles, I had all the plugins which had a git repository placed as git submodules. The rest are also added as bundles with a version number.
Here are the plugins I'm using.
I have already explained s few things about pathogen. Seriously you need to consider using it if you are serious about maintaining your Vim configuration.
Pathogen had to load first. That is why I'm disabling filetype before pathogen and load it later, elsewhere.
This is a really cool file explorer as I've said before. I'm using it with the following config:
Which means I can use ",d" to toggle the tree pane and use "Enter" key to toggle collapsing the tree.
From the same guy behind nerdtree, this plugin makes commenting a breeze.
This plugin gives you a temporary buffer area which never gets saved. Nice to have something jotted temporarily.
This is a nice little plugin which gives you a terminal. It acts pretty similar to a standard bash. However you need to have Python ready in your system (which most common Linux do have usually).
This plugin acts as a frontend to ack. Obviously you need to have ack in the system ready.
This allows the use of some of TextMate snippets in Vim.
This is a frontend for many VCS tools including Git, hg, bzr, SVN, SVK, CVS
This is a very col Git wrapper. If you don't want many VCSs and just need Git, this is the plugin you need.
gitv is a git commit history browser similar to gitk/gitg. It depends on fugitive.
Is a simple buffer explorer plugin.
A pair matching plugin.
A handy plugin if you are into Ruby on Rails web applications.
13. guicolorscheme and csapprox
This enables the use of GUI based Vim colorchemes in just the command line vim version.
CSApprox's more accurate and works most of the time unlike guicolorscheme. The purpose is the same. It enables the use of GUI based Vim colorchemes in just the command line vim version.
This very useful if you plan to use vim as a LaTeX editor/IDE. I've left the configuration in ".vimrc" but I usually install the plugin using package management tools.
I also have a few lines configured in ".gvimrc" file.
What these lines are configuring is how the gvim specific settings. For example I prefer to use Deja Vu Sans Mono font at 11pt as my font. Also I have set that the maximum number of characters per line is 80. After that I have disabled the toolbar, right scrollbar and left scrollbar (when the screen is split). Edit: Since then I've moved all these lines in to my "vimrc".
Click on the image to see the final outcome in actual size. I don't have a fixed colorscheme preference, but I've been using the colorscheme named "monokai" for a while. Edit: I still don't have a fixed preference. However I've added a load of 'colorschemes' to pick from.
If you want to see how things are organized, or grab my configuration files for Vim, you can get them from the GitHub repository. I've commented on my configuration with the file, just in case. Please note that you'll need git to set it up properly (i.e., it uses git submodules). For further instructions please see the README file.
I know this works straight away in latest Fedora, CentOS, RHEL, Ubuntu and Mint Linux systems. I haven't used it on any other systems, but if you want to try, I'm not stopping you.