Why Vim?

Vim is amazing and Free!!! there are millions reasons to love Vim, but I just love the simplicity, fast and customisation, plus its pre-installed on pretty all *nix and Macs! I’ve been using it for a few years as my coding editor and it has been very happy journey, so in this post I’ll tried to tweak my vim setup and serve as a documentation for my future self.

Plugins

There are tons plugins out there - everything you can think of right now or will needed in the future, someone probably already written a vim plugin for it to scratch your itch, but if there isn’t one do what you want, you should be able to write one with help of vast plugin documentations.

Its good to know the structure of Vim folders, so you can check out how things work or where to look if there are problems with installed plugins etc.

General plugin structure

  • ~/.vim/colors/ - files under this folder is treated as colour scheme. e.g :color sunshine will run the ~/.vim/colors/sunshine.vim.
  • ~/.vim/plugin/ - files will get run every time vim starts.
  • ~/.vim/ftdetect/ - files will get run every time vim starts, but its for file type detection as indicated in its name. There should be corresponding autocommand that detect the file type in .vimrc.
  • ~/.vim/ftplugin/ - file type plugin and naming convention matters!!!, when vim sets a buffers filetype to a value, it will try to look for a file in ~/.vim/ftplugin/ or files under ~/.vim/ftplugin/[filetype]/ directory(this make spliting ftplugin files into logical groups.
  • ~/.vim/ident/ - This is similar to ~/.vim/ftplugin it will get run based on their names, this is for identation.
  • ~/.vim/compiler/ - This is similar to ~/.vim/ftplugin it will get run based on their names, this is for compiler related options.
  • ~/.vim/after/ - Files will get load everytime vim start but its after ~/.vim/plugin/, so its possible to override the Vim’s internal files.
  • ~/.vim/autoload/ - autoload is a way to delay the loading of plugin’s code until its actually needed.
  • ~/.vim/doc/ - Docmentation files.
  • ~/.vim/bundle/ - Plugin management folder, all plugins install via vundle is install in here.

Manually manage vim plugin is very painful (even with help of git), threfore the first thing should be doing after install a fresh copy of Vim is to install a plugin manager, because from there you can install/uninstall plugins with a few commands rather than copy files/folders/docs all over the place, the plugin manager will take care them, so you don’t need to worry about the plugin structures etc.

NeoBundle

There are a few choices for plugin manager, noticably Vundle, NeoBundle and VAM, I’ve been using Vundle before, since this is starting from fresh I’m choosing NeoBundle, because its a fork of Vundle but added more features and its seems more active than Vundle.

Vim-fugitive

This is a must have plugin for git, it provide all the useful and familiar git commands inside Vim, so you don’t need to leave vim to do your normla git add, commit and push flow, its worth mention that Gblame and Gdiff are very useful.

Note: it will also add .git/tags file to the tags-option, so Vim can find the tags generated for the repository and TagBar will be able to use the tags file.

vim-colorschemes

Colour scheme is very important, because you’re spending most of the time coding in vim, so its very important to able to pick a colour scheme that’s looks natural to your eyes rather than make your eyes burn, a good colour scheme also can help you identify information like errors/functions or missing } quickly. This plugin contain extensive list of colour schemes including the Solarized use and love by many.

{images show the colour scheme}

Airline

This will make your status line pack with information, the cool thing about it is the integration with other plugins, so other plugin information be part of the airline status line.

Minibufexpl

Its a elegant buffer explorer that shows all buffers on the top of the screen, most of the time those are opened files in Vim, its very pleasant able to see all buffers when you working on multiple files.

Syntastic

Provides syntax check for your files, I’ve it set up to check the syntax on save, it will prompt you if there is syntax error, it works well with airline.

Nerdtree

A files/folders explorer that show folders/files in tree format, its useful to be able to see the structure of project.

{images nerdtree}

Tagbar

Very handy plugin when you edit/browse codes, it basically provide tags for function names, variables or classes etc, so you can jump to those functions like normal vim tags, this plugin will make navigate throug the code very easy.

{image showing tag bar}

Note: Tagbar will require ctags to generate an index/tag file of most programming languages which tagbar will be able to manage the tags.

Debug Vim

For any reason if Vim is giving your errors, you’ll able to make Vim more verbose which will show you what function is called and what buffer is used etc, this is very handy when you try to debug what vim is doing, this command save me many times!

vim -V10vimlog file-to-open - This is set the verbose level to 10 and store all the log inside vimlog file in the current directory, level 15 will show even more output

.vimrc

I’ve spent fair amount of time to clean up my .vimrc file, now it should be more readable, there will be evovling changes over time.