1

In VIM I've, all my tabs are 2 spaces. But when I push to github, they get converted to 4 spaces. Can anyone help me figure out how to prevent them from getting converted to 4 spaces?

My vimrc file:

call pathogen#infect()
call pathogen#runtime_append_all_bundles()

" search
set hlsearch                  " highlight the search
set incsearch                 " incremental search
set ignorecase                " search ignoring case
set showmatch                 " show matching bracket

" colors
set background=dark
let g:solarized_termcolors=8 " proper solarized coloring
colorscheme peachpuff

" syntax
syntax on
filetype on                   " Enable filetype detection
filetype plugin on            " Enable filetype-specific plugins
filetype indent on            " Enable filetype-specific indenting

set ruler                     " show the line number on the bar
set more                      " use more prompt
set autoread                  " watch for file changes
set number                    " line numbers
set hidden
set noautowrite               " don't write old file out when switching files
set lazyredraw                " don't redraw when don't have to
set showmode
set showcmd
set nocompatible              " vim, not vi
set autoindent smartindent    " auto/smart indent
set smarttab                  " tab and backspace are smart
set tabstop=2                 " 6 spaces
set shiftwidth=2
set scrolloff=5               " keep at least 5 lines above/below
set sidescrolloff=5           " keep at least 5 lines left/right
set history=200
set backspace=indent,eol,start
set linebreak
set cmdheight=2               " command line two lines high
set undolevels=1000           " 1000 undos
set updatecount=100           " switch every 100 chars
set complete=.,w,b,u,U,t,i,d  " do lots of scanning on tab completion
set ttyfast                   " we have a fast terminal
set noerrorbells              " No error bells please
set shell=bash
set fileformats=unix
set ff=unix
set wildmode=longest:full
set wildmenu                  " menu has tab completion
set laststatus=2
set diffopt=filler,iwhite     " ignore all whitespace and sync

" scss formatting
autocmd BufRead,BufNewFile *.scss ""set ft=scss.css

" jade formatting
autocmd BufRead,BufNewFile *.jade setlocal ft=jade noexpandtab
autocmd FileType jade :setlocal sw=2 ts=2 sts=2

autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
autocmd Filetype javascript setlocal ts=2 sw=2 sts=0 noexpandtab
bob_cobb
  • 2,229
  • 11
  • 49
  • 109

2 Answers2

3

The standard representation of a tab character is 8 spaces. In reality, the tab is a control character and as such doesn't have an associated glyphs or a set width. This allows most programs to offer a way to modify how it is displayed but no program ever change its width because it doesn't have one to start with: a tab is still a tab, no matter the value of tabstop.

Your Vim settings only alter how tabs are displayed in Vim: they have no bearings on how they are displayed outside of Vim.

You have two solutions:

  • set GitHub and Vim to use the same tab width

  • use spaces


Since we are at it…

set background=dark
let g:solarized_termcolors=8 " proper solarized coloring
colorscheme peachpuff

You can delete the solarized line if you don't use it and set background is useless because your colorscheme takes care of that.

set noautowrite

is also useless because autowrite is off by default.

And

call pathogen#runtime_append_all_bundles()

serves no purpose whatsoever.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • `set background` is *not* useless. It is one of the solarized settings, similar to `g:solarized_*`. In fact, some colorschemes do check `&background` before setting `Normal` highlighting (which, according to the doc, will reset `&background`) and solarized is one of them. – ZyX Sep 29 '13 at 14:50
  • Also note that `set noautowrite` may not be useless because `set autowrite` could be specified in `/etc/vimrc`/`/etc/vim/vimrc` or whatever is used by your linux distribution. – ZyX Sep 29 '13 at 14:52
  • 2
    What *is* wrong in the settings is `set nocompatible`. According to the doc this resets `set hlsearch`, `set incsearch`, `set more`, `set ruler`, `set showcmd` and `set showmode` making all these definitions useless. @bob_cobb should have placed `set nocompatible` at the top of the vimrc. – ZyX Sep 29 '13 at 14:58
  • Its position is also wrong because solarized colorscheme requires vim being in `nocompatible` mode (or, more specific, at least `cpoptions` setting that allows line continuation; maybe also some other options). Thus if OP has not already had vim running in `nocompatible` mode due to presence of the `vimrc` file (vim automatically sets `nocompatible` if it finds `.vimrc`) this vimrc would be failing. – ZyX Sep 29 '13 at 15:03
  • @ZyX, he is not using solarized so any setting related to that colorscheme is redundant and setting `background` to `dark` just before the chosen colorscheme sets it to `light` doesn't make much sense. – romainl Sep 29 '13 at 15:05
  • @ZyX, and `nocompatible` is almost totally useless as it is set automatically if a `~/.vimrc` is found. At this point of the initialization, all the options are simply set accordingly whether/wherever you have `set nocompatible` in your `~/.vimrc`. The only use of that line in one's `vimrc` is for `$ vim -u /pat/to/my/vimrc`. – romainl Sep 29 '13 at 15:12
  • If you know you may want to source vimrc with `-u` it is better to set it rather then not. It must be the first one in any case though, not like here: all options mentioned in `:h 'compatible'` are always reset on `set *compatible`, no matter whether or not `&compatible` value changed. Even Gentoo maintainers agree on this, setting `nocompatible` in `/etc/vim/vimrc` and so does `vimrc_example.vim` distributed with vim. I have not noticed that OP does not use `solarized` though. – ZyX Sep 29 '13 at 16:00
  • Yes for the scnario and yes for that line at the top of the vimrc. – romainl Sep 29 '13 at 18:34
  • Yeah, what ZyX said. I need `call pathogen#runtime_append_all_bundles()` in order to use NerdTree also. – bob_cobb Sep 29 '13 at 22:01
  • ZyX said many things and that function is deprecated: it is a proxy for incubate() and incubate() is already called by infect(). – romainl Sep 30 '13 at 06:04
0

I would recommend reading this on how to change tabsize for Github

There appears to be a browser extension called Stylish that changes tabs in Github by downloading the style "Better sized tabs in code"

Download the browser extension and use the style and change the tab spacing to two space tabs.

Hope this helped!

Community
  • 1
  • 1
Domecraft
  • 1,645
  • 15
  • 26