Skip to main content

My Vim Configuration

My Editors

I have used many text editors. Some for specific tasks such as LaTeX editing (Eg: Texmaker), coding (Eg: gedit with plugins) and the others for more generic text editing.

As a system administrator I have been using Vi/Vim all along for editing configuration files and the likes. It was always convenient as almost every Unix system has vi/vim. For me the first Unix editor I used was Emacs. I felt more at home with Emacs key combinations than a hard to fathom Vim modes. Time passed and after a little while, I got used to basic Vi concepts. Since then all of my editing in command line was done in vi/vim.

As I've said recently, I have been transforming myself from a sysadmin to a sysadmin/developer kind of person. For coding purposes I used gedit. Some people might think of gedit as the notepad.exe of Linux, but that's so not correct. In fact gedit is a powerful text editor with a lot of plugins to extend it's capabilities. For example there there are plugins for LaTeX, Python consoles, bash terminal, snippet completing, snap open, integration with VCSs, smart tab/space, code formatter, class browser, Ruby on Rails modes, encryption, smart indentation, ToDo list, web browser, full screen editing, split screen, PO file editing, markdown preview, etc. among other things. As you can see, it's no toy editor. It's fully fledged editor for serious work.

Let's get back to the topic. I love gedit and I use it whenever I need. But from a couple months ago, my main editor is Vim. Vim is the most popular improved clone of the original Vi editor. It's been around for about 18 years. So you too might be wondering "Why, oh WHY, do those #?@! nutheads use vi?" or why Vim, an 18 year old, hard to learn terminal based text editor?!

I can take a lot of posts to answer that or assume you will try it yourself and get into your own terms with Vim. I'll go with the latter and share with you what my current (as of 15 July 2009) Vim configuration is.




My Vim configuration: Gavim


Note: I'm working on a Fedora Linux system. By default there's a very decent Vim configuration in Fedora. So I took the default global Vim configuration file in a Fedora 10/11 system and did the tweaks to get it to my liking. As you would have expected, a significant part of the vimrc is straight from Fedora.

Some of the plugins I use are taken from vim.org, while some are taken from their sources (mostly from GitHub repositories).

And oh, I only use Vim not gVim (Vim with a GUI).


In the first few lines of my Vim configuration file is an entry which says,
Eg:
set nocompatible

which is to tell that it shouldn't try to be compatible with older Vi, and just use the Vim behaviour. I also liked to have the editor show the line numbers on left. There are other other small tweaks I like to have.

All these things are included in my Vim configuration files repository, and the files are well (hopefully) commented. So anyone interested can refer to my vimrc and find more about those.

One thing to notice is I'm using the key "," as my leader key.
Eg:
let mapleader = ","

Vim 7 also has built in spell checking abilities. I find this very useful as I use Vim for every typing needs these days. I have configured 2 keyboard shortcuts to enable and disable spell checking.
Eg:
map <F8> <Esc>:setlocal spell spelllang=en_us<CR>
map <F9> <Esc>:setlocal nospell<CR>

This means that I can press F8 key to turn spell checking on with language set as English (USA) and turn off by pressing F9.

I also like to have the ability fold/unfold code blocks when coding. For this I used another Vim built in.
Eg:
setlocal foldmethod=syntax
setlocal nofoldenable

which sets the folding based on syntax (i.e. programming language), and doesn't enable it by default.

I also have set a place holder character to be displayed while typing "space" and "tab" characters. These are displayed until you type a new character after the tab/space.
Eg:
set list
set listchars=trail:⋅,nbsp:⋅,tab:▷⋅

And BTW, the theme (colour scheme) I'm using for Vim is called "darkblack". It's a dark theme which provides very good readability. It is included in my repository.

To get the best view for most of the themes and the smoother fonts you need to tell Vim to use 256 colors in the terminal.
Eg:
set t_Co=256

As you already know most Linux systems have excellent font rendering. The default on Ubuntu systems are not good, but other systems like Fedora was having quality font rendering by default for a while. So having a nice colour theme with smooth fonts is a very pleasant experience. See the screenshots for proof. :)

Those are the major Vim features I'm using. You can see everything in the configuration files. Now let's check the major Vim plugins I'm using.



Plugins I use

Different plugins may have different installation steps. Check the "Readme" files of the plugin for more details. Generally it involves copying the .vim file in the plugin package into the plugin directory of the vim configuration directory.
Eg:
$ cp ./NERD_tree.vim ~/.vim/plugin/

1. NERDTree

The NERDTree plugin by Martin Grenfell is an excellent file system tree browser plugin for Vim.

You can set the exact key binding to activate NERDTree by specifying
Eg:
nnoremap <leader>d :NERDTreeToggle<cr>

Once installed you can toggle the tree browser pane by pressing [leader]d in command mode. Eg: ,d

I have also set this:
Eg:
let NERDTreeMapActivateNode='<CR>'

which aloows you to toggle the expanding of directory views by pressing "Return" (Enter) on the directory node.




2. Scratch

Scratch gives a temporary scratch buffer area which will be discarded when you exit vim. This is not saves in a file. It's quite useful to jot down something quick while you are editing.


I'm using s to toggle the scratch area.
Eg:
function! ToggleScratch()
if expand('%') == g:ScratchBufferName
quit
else
Sscratch
endif
endfunction

map <leader>s :call ToggleScratch()<CR>

3. Snipmate.vim


Snippet completion is a very useful thing to have when you are coding. This is a feature which can be found on almost all Integrated Development Environments (IDE). Snipmate is a cool plugin with brings some of snippets from the popular test editor TextMate to Vim.

Martin Grenfell have a useful collection of snippets to use with Snipmate.vim.



4. Bufexplorer

This is a simple Buffer Explorer plugin which with list the open buffers and let you go to any of them.


5. VCSCommand

This plugin takes care of working with different version controlling systems such as Git, Bazaar, Subversion, CVS, etc.



How to use this for you

That's all I have to tell about my Vim configuration for now. Some of the general configuration and some plugins I use are not mentioned in this post. But you are welcome to check it out.

Just in case if you are interested in using these for your Vim setup, be my guest. Be informed though. This works fine with Fedora 10/11 systems. I haven't checked on other systems, which might ot might not have differently compiled Vim setups. In any case you are welcome to grab the files and tweak it to your liking.

Here's the link to my Vim files repository: gavim

You can find more instructions in the "Readme" file there.

Comments

  1. I also switched to Vim couple of months ago..and before that I had been troubled for a long time in finding the perfect text editor for me. Vim turned out to be the one which seemed to fit in nicely to my workflow (same as Git did).

    I also have a very similar Vim config to yours.

    Apart from the plugins you mentioned I use Tim Pope's rails.vim - http://rails.vim.tpope.net/ It's makes the Rails development so easy with Vim.

    Also, I can post code snippets directly to Gist thanks to this plugin - http://www.vim.org/scripts/script.php?script_id=2423

    BTW, What is the color scheme you are using? Try VividChalk it's a great coding.

    ReplyDelete
  2. Thanks Lakshan for the nice additional information.

    I know how you feel when all of your tools work perfect like Ruby, Vim, Git, Linux, etc. :)

    In fact I use both Gist and rails.vim plugins. They are in my repo, but didn't list in the post for simplicity.

    The color scheme I'm using is called "darkblack" by Matthew Jimenez. It's a modification of the darkblue scheme by Bohdan Vlasyuk. I've tried both darkblue, VividChalk and a few others like VibrantInk and so on. But I found darkblack scheme to have a good balance between dark and cool on the eye. The readability was better on it than many of the dark color schemes I've tried.

    There are few more color schemes in my repo which I found nice, all from public sources of course. :)

    Also I prefer DejaVu Sans Mono as the coding font.

    Note: I tried gedit again today.... make it yesterday. Rails related plugins seem to have improved too. That's a good alternative for people who wants a GUI editor. Hopefully Redcar should join the race soon too.

    Thanks again mate for stopping by.

    ReplyDelete
  3. http://dailyvim.blogspot.com

    ReplyDelete
  4. Anonymous7:27 AM

    Hi there,
    Thanks for the vimrc. Came here via search for 'vim snap open'. Looking for something similar to textmate or gedit snap open, (regex based). Haven't found a suitable vim plugin yet. Know of any?

    ReplyDelete
  5. @Anonymous:
    FuzzyFinder-TextMate is one good thing I've used. Sadly the author gave up maintaining that because a dependency script kept changing all the time.

    I think you can get it working with fuzzyfinder 2.16. However you need to have a vim installation built with Ruby support.

    @Rajika:
    Thanks for the link.

    ReplyDelete
  6. Update: I am now completely using gVim (Vim with a GUI) most of the time. It's more convenient to use with things like LaTeX suite plugin. I'm using a different colorscheme (railscasts) now and I also added a few more plugins and tweaks.

    If you for some reason want to see the current Vim configuration I use, check the GitHub repo link in the post.

    ReplyDelete
  7. Anonymous10:21 AM

    I think your link that show your VimConfiguration has been crashed
    not sure but whenever I click it google error pop up saying this link has been crashed

    ReplyDelete
  8. @Yoo: It seem to work for me. If you still have problem accessing it this is the link:
    http://github.com/gaveen/gavim

    ReplyDelete
  9. Anonymous6:17 PM

    This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

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