Setting tabwidths to match the project settings in GIT and VI

I use Git and VI(m) quite a bit, and in the Liferay project the source format rules define that leading whitespace character is tab (with potentially trainling spaces before the rest of the line in some cases, but that's another story).

Furthermore, tab width is 4.

Since I'm commonly in the command line I hate that the source doesn't represent the same way that I see it in the IDE, especially when reviewing diffs since most console output has tab width of 8.

GIT

So the question is "How do I make git output use tab width of 4 instead of the default 8?"

After searching long without success, I finnally learned that git uses the "pager" paradigm for displaying diffs, and that the external pager can be tuned in the ~/.gitconfig file.

Awesome!

So, to adjust the tab width add the following to your config:

[core]
    pager = less -FXRS -x4

 

This tells git to use "less" command as the external pager, then it passes some settings to less, but most importantly it sends the setting:

-x<n>

which sets the tab width.

VI(m)

Now to get the same result in VI(m) you can edit the ~/.vimrc file. Coolness!

set tabstop=4
set ts=4
set shiftwidth=4
set autoindent

 

Great! That's it.

Now all my important console output has the proper tab widths (and I can tell if I messed up my bchan style formatting).  

;)

Blogs
Nice!! Here are two settings to vi(m) that I use:

syntax enable
set number

It sets syntax highlight for know file formats (java, xml, html...) and add at the beginning of the line a number identifying the line.
Thanks Ray, I never remember those settings for VIM. Now finding the .vimrc file on windows can be fun!