Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Created December 27, 2010 15:14
Show Gist options
  • Save lukaszkorecki/756203 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/756203 to your computer and use it in GitHub Desktop.
Shows softabs (spaces instead of tabs) as real tabs, but still saves spaces. I don't get it. Don't worry - neither do I.
" shows expanded tabs (2 spaces) using
" vim's listchars (which only work with
" hard tabs) but still saves spaces instead of tabs
" needds following settings:
" set softtabstop=2
" set shiftwidth=2
" set tabstop=2
" set expandtab
" set list
" set listchars=tab:▸\ ,eol:.
" but it can be made more flexible
function! g:ShowIndents()
let line_num = line(".")
setlocal noexpandtab
" FIXME this regex needs to work only with
" something like ^(\ \ )*"
silent exe '%s= =\t=g'
setlocal nomodified
exe "goto ".line_num
endfunction
function! g:HideIndents()
let line_num = line(".")
setlocal expandtab
retab
setlocal nomodified
exe "goto ".line_num
endfunction
"auto commands
autocmd BufWritePre *.rb call g:HideIndents()
autocmd BufWritePost *.rb call g:ShowIndents()
autocmd BufRead *.rb call g:ShowIndents()
autocmd BufNewFile *.rb call g:ShowIndents()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment