Get me some of that WYSIWYGI know what you’re thinking – VIM is awesome because its all terminal. And there is no reason to give that up! I haven’t, especially for those quick edits. However when it comes to coding for any length of time, my goto editor has been one where VIM is wrapped in WYSIWYG goodness. I’m talking about the likes of gVim alternatives such as vim-gnome (Linux Gnome), vim-gtk (Linux) or macVim (OSX). Pick one depending on the platform. I use gnome-vim on Debian and macVIM on OSX.
For Debian based…
$ sudo apt-get install vim-gnome
For OSX visit macVIM siteAnd so the fun begins! First I’ll show you how I got tabs working in a helpful manner where each file you opened from the command line would open up as a new tab within the same session window. This was easily accomplished using a specially crafted alias which was placed in the
Here I use macVIM but one could easily substitute gvim on Linux. Now try opening a file or two and they should open in separate tabs.
alias gvi='mvim --servername VIM --remote-tab-silent'
Switching tabs can be performed via the mouse but I prefer using
gvi /etc/passwd /etc/hosts gvi ~/.bash_profile
command + shift + ]and
command + shift + [key stokes on OSX which work out of the box on macVIM. However on Linux to get a similar functionality, I had to add a special key mapping to
~/.gvimrc. Since I wanted to keep the same feel as on OSX, I substituted the
altkey in place of
commandkey found on Macs.
All we are doing is making use of the
" Map tab switching map
gt map gT
gTcommands to switch between next and previous tab by mapping it to shortcut keys.
Add some colorWhile the default color scheme that comes with vim is pretty straightforward, it lacked the vibrant and cheerful syntax highlighting found in those other editors. Not a problem though, thanks to Vim Color Schemes. My favorite one, which I ended up using was Vividchalk. Simply download the color theme file of your choice (such as vividchalk.vim) to
~/.vim/colors/and set it via .gvimrc.
" Set color scheme syntax on set background=dark colorscheme vividchalk " Optionally set font and transparency set guifont=Monaco:h13 " set guifont=Monospace\ Bold\ 10.5 set transparency=15
Better searchingSearching is an important part of editing and so there are few things we can do to improve VIMs default search capabilities.
" Search related set incsearch set hlsearch set ignorecase set smartcase
incsearchmakes search incremental so that as you type the search keyword (via /keyword in command mode), VIM will start highlighting and transporting you to that location.
hlsearchis useful in that it highlights all keywords matching the search criteria. The last two,
smartcasetogether provide a smarter way to search by making any keyword typed all in lowercase to be a case insensitive search while still retaining case sensitivity for mixed case (e.g /FooBar won’t find foobar but /foobar will find bothFoobar and foobar)
Few more enhancements for codersI’ll close off with a few more enhancements that can come in handy when writing code. First is to turn on line numbers by default and it looks great with my color scheme. I also prefer seeing a vertical guide fixed to 80 characters in order to keep me in check as to the length of my code. Along the same line, its also a good practice to catch those trailing white spaces which can appear ugly when viewed through a visual diff tool. Finally having auto completion turned on may come in handy, especially if you suffer from short term memory like I do :)
To activate a language specific auto completion, use
Ctrl-X Ctrl-Ocombination while on the insert mode. Besides using language specific auto completion, vim also supports a smart auto completion which relies on text already found in the document being edited, which can be activated using
Ctrl-Nafter typing part of the word. It is quite useful when you want to retype a previously declared variable or method name.
There are a ton of other tips that can make VIM so much better for coders such as folding code blocks or visually showing marks made via ma, mb etc.. Chances are, if you can think of a feature you’d like to have, there’s probably a plugin or built in to make that happen!
I’ll leave you with this great post which has few more useful tips.