Skip to main content

My Vim Configuration: Take 2

More than a year ago I wrote about my story of switching (completely) to Vim as my primary editor. If you have worked in a Unix/Linux system seriously then you know why your editor (whatever it maybe) is a big deal. If you don't, let's just say as a SysAdmin and a budding DevOps type guy, my editor is a serious thing to me. So here's my Take Two.

Why?

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. Also importantly, I started using gvim (package name vim-X11 in Fedora) most of the time instead of just the terminal based vim. Edit: Since then I've moved back to using just vim mainly and gvim as a secondary. Apart from being leaner, it makes it possible to work in full-screen mode.

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. What I actually wanted to have was 'relativenumber' (commented-out line) which shows the line number relative to the line where the cursor is. This is handy when I'm deleting lines or yanking them. Unfortunately it's only available from vim version 7.3 (Fedora as of this writing uses a revision in 7.2 range). If I wanted to know the actual line number, I could always look at the status line at the bottom anyway. I hope Fedora updates to Vim 7.3 soon. Edit: It has. :) But I'm no longer using 'relativenumber' because it can be a little distracting.

'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.

The options 'wildmenu' and 'wildmode' works together to make the vim command line operate more like bash (i.e., shows the completion options when the tab key is pressed instead of traversing between options) and with a prettier menu mode. The latter invokes the first, if it's enabled.

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.: ,?) to show the changes made since the last save.

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.

1. pathogen
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.

2. nerdtree
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.

3. nerdcommenter
From the same guy behind nerdtree, this plugin makes commenting a breeze.

4. scratch
This plugin gives you a temporary buffer area which never gets saved. Nice to have something jotted  temporarily.


5. conque
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).


6. ack

This plugin acts as a frontend to ack. Obviously you need to have ack in the system ready.

7. snipmate

This allows the use of some of TextMate snippets in Vim.

8. vcscommand
This is a frontend for many VCS tools including Git, hg, bzr, SVN, SVK, CVS

9. fugitive
This is a very col Git wrapper. If you don't want many VCSs and just need Git, this is the plugin you need.

9.1 gitv

gitv is a git commit history browser similar to gitk/gitg. It depends on fugitive.

10. bufexploreer

Is a simple buffer explorer plugin.

11. matchit

A pair matching plugin.

12. rails
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. 

14. latex
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".


The Result


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.

Comments

  1. Anonymous4:34 AM

    Thank your for sharing and explaining your work.

    ReplyDelete

Post a Comment

Popular posts from this blog

Howto Migrate from Thunderbird to Evolution

I know some of you are asking why , rather than how , regarding migration from Mozilla Thunderbird to Evolution. Maybe that's why there are lot of Evolution to Thunderbird migration guides, but not many vice-versa. Fear not, here is a guide, to assist who dare to migrate from Thunderbird to Evolution. The techniques described here are tested with the newer versions of both the software, namely Thunderbird 2.0.0.4 and Evolution 2.10.2. On higher versions also this should work without an issue. I think Mozilla people are doing a wonderful job with both Firefox and Thunderbird . From my point of view Firefox is the best general purpose web browser around. It beats most proprietary browser in speed, stability, security, modularity, etc. (and don't start commenting the so and so browsers are greater or so and so is cool too. I know they may be, Fx is simply my choice. This also applies to any comparisons with Evolution too :) However Fxs' counterpart in e mail business, is not y...

Howto Install Docky on Fedora

If you know me personally, then you know that I'm a big fan of GNOME Do . As a keyboard savvy person I use Do extensively. Do is an application launcher similar to the Mac app Quicksilver. However the GNOME Do team has been putting a lot of research and development into it from the initiation. Result: probably the best application launcher out there for any platform. Some months ago, Do included an interesting theme called Docky which made the launcher acts as a dock (a la Mac, Avant, Cairo Dock, etc.). With the integration of GNOME Do, there's no need to say that Docky was super cool. And it started gaining features in a high speed. Ultimately Docky was getting so developed that it became a separate project. Installing GNOME Do on a Fedora system is as easy as: $ sudo yum install gnome-do There are some packages with the names starting from gnome-do-plugins*. With the addition of these GNOME Do can truly enhance your desktop experience. Give it a fair try, I'm pretty...

Howto Setup a Subversion (svn) Repository for a Rails Project + Bonus

Setting up a Subversion (svn) repository is something development teams have to do fairly regularly, not that I want to use Subversion. :) If you listen to me, go use Git . Subversion is undoubtedly very good. But after using Git for about a year, you can't simply get me to switch back. Git is that good. :) I've written about Git before . In cases where you can't use Git (or you feel too castrated by TortoiseSVN, pardon me for the pun) you can use Subversion. In this post I'll go through the steps you have to follow to get a basic Subversion setup up and running on a CentOS 5 Linux host. However I think you should be able to use this on other Linux distros too. There's more than one way to host a Subversion repo. I'm going to stick with one way involving WebDAV. Don't mind the buzz word. It's the most common usage for this purpose. If you want a repository where you want to checkout and commit remotely, this is an easy way of getting it done. In addition...