Skip to content

Instantly share code, notes, and snippets.

@osyoyu
Created August 21, 2012 15:03
Show Gist options
  • Save osyoyu/3416288 to your computer and use it in GitHub Desktop.
Save osyoyu/3416288 to your computer and use it in GitHub Desktop.
ftplugin/ruby.vim
" Replace 2 space-indents to tabs on open
" and switch them back on close
function SpacesToTabs()
set ts=4
set sw=4
set sts=0
set noexpandtab
try
%s@^\v(%( {2})+)@\=repeat("\t", len(submatch(1))/2)@
catch
finally
1
endtry
endfunction
function TabsToSpaces()
set ts=2
set sw=2
set sts=0
set expandtab
retab
endfunction
autocmd BufEnter * call SpacesToTabs()
autocmd BufWritePre * call TabsToSpaces()
autocmd BufWritePost * call SpacesToTabs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment