Skip to content

Instantly share code, notes, and snippets.

@wikitopian
Created August 16, 2012 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wikitopian/3371393 to your computer and use it in GitHub Desktop.
Save wikitopian/3371393 to your computer and use it in GitHub Desktop.
Dealing with tabs and spacing in Vim
" The final answer to the Tab Question
set colorcolumn=80
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
set list listchars=tab:»·,trail:·
function! SwitchTab()
setlocal expandtab!
endfunction
vnoremap <Leader><tab> <Esc>:call SwitchTab()<CR>
inoremap <Leader><tab> <Esc>:call SwitchTab()<CR>
nnoremap <Leader><tab> <Esc>:call SwitchTab()<CR>
augroup wspace
autocmd!
" Visual warning about trailing whitespace and mixed up spacing
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$\| \+\t\|\t \+/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$\| \+\t\|\t \+/
autocmd InsertEnter * match ExtraWhitespace /\s\+$\| \+\t\|\t \+/
autocmd InsertLeave * match ExtraWhitespace /\s\+$\| \+\t\|\t \+/
autocmd BufWinLeave * call clearmatches()
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment