Something is changing spaces to tabs on default install #193

Closed
mrpollo opened this Issue Mar 18, 2013 · 5 comments

Comments

Projects
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
endif

" 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
endif
" 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('/')
    :%s/\s\+$//e
    call setpos('.', save_cursor)
    call setreg('/', old_query)
endfunction
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
endif

execute pathogen#infect()
Owner

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?

[alias]
    # 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

[apply]
    # Detect whitespace errors when applying a patch
    whitespace = fix

[core]
    # 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

[color]
    # 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
[merge]
    # 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 "git@github.com:"]
    insteadOf = "gh:"
    pushInsteadOf = "github:"
    pushInsteadOf = "git://github.com/"
[url "git://github.com/"]
    insteadOf = "github:"
[url "git@gist.github.com:"]
    insteadOf = "gst:"
    pushInsteadOf = "gist:"
    pushInsteadOf = "git://gist.github.com/"
[url "git://gist.github.com/"]
    insteadOf = "gist:"

[push]
    default = matching
[user]
    email = mrpollo@gmail.com
    name = Ramón Roche
Contributor

oschrenk commented Mar 21, 2013

I believe it is the combination of

[core]
    whitespace = space-before-tab,indent-with-non-tab,trailing-space

[apply]
    whitespace = fix

From the documentation

core.whitespace
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 https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig#L35

Contributor

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 https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig#L35

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