Wednesday, January 25, 2012

Configure vim for git

So if are using VIM for git commits, sometimes just to open a file and quickly edit it you might have encountered an issue. By default tab key inserts tab characters which you don’t want as if you care about alignment then these tabs wont show up  right in some other editor.

To tell vim not to use tab char but use spaces instead copy and paste these three in you .vimrc

set tabstop=2
set shiftwidth=2
set expandtab


Also this post is useful if you like to see the trailing whitespaces
http://vim.wikia.com/wiki/Highlight_unwanted_spaces

All you need is these 5 lines:

highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@ autocmd InsertLeave * match ExtraWhitespace /\s\+$/


for:
- highlight trailing whitespace in red
- have this highlighting not appear while you are typing in insert mode
- have the highlighting of whitespace apply when you open new buffers

No comments:

Post a Comment