Something is changing spaces to tabs on default install #193

mrpollo opened this Issue Mar 18, 2013 · 5 comments


None yet
3 participants

mrpollo commented Mar 18, 2013

When I push code to any repo sometimes some of the new lines get changed from 2 spaces to tabs, has anyone experience something like this?

Here is my vimrc

" Make Vim more useful
set nocompatible
" Use the OS clipboard by default (on versions compiled with `+clipboard`)
set clipboard=unnamed
" Enhance command-line completion
set wildmenu
" Allow cursor keys in insert mode
set esckeys
" Allow backspace in insert mode
set backspace=indent,eol,start
" Optimize for fast terminal connections
set ttyfast
" Add the g flag to search/replace by default
set gdefault
" Use UTF-8 without BOM
set encoding=utf-8 nobomb
" Change mapleader
let mapleader=","
" Don’t add empty newlines at the end of files
set binary
set noeol
" Centralize backups, swapfiles and undo history
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
if exists("&undodir")
    set undodir=~/.vim/undo

" Respect modeline in files
set modeline
set modelines=4
" Enable per-directory .vimrc files and disable unsafe commands in them
set exrc
set secure
" Enable line numbers
set number
" Enable syntax highlighting
syntax on
" Highlight current line
set cursorline
" Make tabs as wide as two spaces
set cindent
set smartindent
set autoindent
set tabstop=2
set expandtab
set shiftwidth=2
set softtabstop=2
" Show “invisible” characters
set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
set list
" Highlight searches
set hlsearch
" Ignore case of searches
set ignorecase
" Highlight dynamically as pattern is typed
set incsearch
" Always show status line
set laststatus=2
" Enable mouse in all modes
set mouse=a
" Disable error bells
set noerrorbells
" Don’t reset cursor to start of line when moving around.
set nostartofline
" Show the cursor position
set ruler
" Don’t show the intro message when starting Vim
set shortmess=atI
" Show the current mode
set showmode
" Show the filename in the window titlebar
set title
" Show the (partial) command as it’s being typed
set showcmd
" Use relative line numbers
if exists("&relativenumber")
    set relativenumber
    au BufReadPost * set relativenumber
" Start scrolling three lines before the horizontal window border
set scrolloff=3

" Strip trailing whitespace (,ss)
function! StripWhitespace()
    let save_cursor = getpos(".")
    let old_query = getreg('/')
    call setpos('.', save_cursor)
    call setreg('/', old_query)
noremap <leader>ss :call StripWhitespace()<CR>
" Save a file as root (,W)
noremap <leader>W :w !sudo tee % > /dev/null<CR>

" Automatic commands
if has("autocmd")
    " Enable file type detection
    filetype on
    " Treat .json files as .js
    autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript

execute pathogen#infect()

mathiasbynens commented Mar 18, 2013

Check your .gitconfig.

mrpollo commented Mar 21, 2013

Here is my gitconfig,

I found that my issue only happens when i pull --rebase, would [apply] whitespace have anything to do?

    # View the SHA, description, and history graph of the latest 20 commits
    l = log --pretty=oneline -n 20 --graph
    # View the current working tree status using the short format
    s = status -s
    # Show the diff between the latest commit and the current state
    d = !"git diff-index --quiet HEAD -- || clear; git diff --patch-with-stat"
    # `git di $number` shows the diff between the state `$number` revisions ago and the current state
    di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d"
    # Pull in remote changes for the current repository and all its submodules
    p = !"git pull; git submodule foreach git pull origin master"
    # Clone a repository including all submodules
    c = clone --recursive
    # Commit all changes
    ca = !git add -A && git commit -av
    # Switch to a branch, creating it if necessary
    go = checkout -B
    # Show verbose output about tags, branches or remotes
    tags = tag -l
    branches = branch -a
    remotes = remote -v
    # Credit an author on the latest commit
    credit = "!f() { git commit --amend --author \"$1 <$2>\" -C HEAD; }; f"
    # Interactive rebase with the given number of latest commits
    reb = "!r() { git rebase -i HEAD~$1; }; r"
    # Undo a `git push`
    undopush = push -f origin HEAD^:master

    # Detect whitespace errors when applying a patch
    whitespace = fix

    # Use custom `.gitignore` and `.gitattributes`
    excludesfile = ~/.gitignore
    attributesfile = ~/.gitattributes
    # Treat spaces before tabs, lines that are indented with 8 or more spaces, and all kinds of trailing whitespace as an error
    whitespace = space-before-tab,indent-with-non-tab,trailing-space

    # Use colors in Git commands that are capable of colored output when outputting to the terminal
    ui = auto
[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
[color "status"]
    added = yellow
    changed = green
    untracked = cyan
    # Include summaries of merged commits in newly created merge commit messages
    log = true

# Use `origin` as the default remote on the `master` branch in all cases
[branch "master"]
    remote = origin
    merge = refs/heads/master

# URL shorthands
[url ""]
    insteadOf = "gh:"
    pushInsteadOf = "github:"
    pushInsteadOf = "git://"
[url "git://"]
    insteadOf = "github:"
[url ""]
    insteadOf = "gst:"
    pushInsteadOf = "gist:"
    pushInsteadOf = "git://"
[url "git://"]
    insteadOf = "gist:"

    default = matching
    email =
    name = Ramón Roche

oschrenk commented Mar 21, 2013

I believe it is the combination of

    whitespace = space-before-tab,indent-with-non-tab,trailing-space

    whitespace = fix

From the documentation

indent-with-non-tab treats a line that is indented with space characters
instead of the equivalent tabs as an error (not enabled by default).

So all indentations with spaces are treated as error, which are automatically
"fixed" to tabs because you use whitespace = fix, which tells git not to warn,
or to error but to automatically change it.

mrpollo commented Mar 21, 2013

and its important to note that this only happened when text was indented with more than 8 spaces exactly was line 35 states


oschrenk commented Mar 22, 2013

and its important to note that this only happened when text was indented with more than 8 spaces exactly was line 35 states

This works as documented here. You can somewhat control the behaviour with

tabwidth=<n> tells how many character positions a tab occupies; this is relevant for indent-with-non-tab and when git fixes tab-in-indent errors. The default tab width is 8. Allowed values are 1 to 63.

So change the tabwidth to your liking or remove the entries from your gitconfig.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment