Skip to content

Instantly share code, notes, and snippets.

@wolever
Created January 22, 2012 20:58
Show Gist options
  • Save wolever/1658762 to your computer and use it in GitHub Desktop.
Save wolever/1658762 to your computer and use it in GitHub Desktop.
Vim functions to change tab treatment
" Usage:
" - copy+paste into ~/.vimrc or ~/.vim/plugin/tabtreatment.vim
" - Call with ':call HardTabs(...)' or ':call SoftTabs(...)'
" HardTabs([width=8]): Sets up the current buffers so that:
" - '\t' is 'widith' wide
" - '<tab>' inserts a '\t'
" - '>>' shifts one tab
fun! HardTabs(...)
let width = (a:0 > 0? a:1 : 8)
let &l:tabstop=width
let &l:softtabstop=width
let &l:shiftwidth=width
let &l:expandtab=0
endfun
" SoftTabs([softWidth=4, [hardWidth=8]]): Sets up the current buffers so that:
" - '\t' is 'hardWidth' wide
" - '<tab>' inserts 'softWidth' spaces
" - '>>' shifts with 'softWidth' spaces
fun! SoftTabs(...)
let softWidth = (a:0 > 0? a:1 : 4)
let hardWidth = (a:0 > 1? a:2 : 8)
let &l:tabstop=hardWidth
let &l:softtabstop=softWidth
let &l:shiftwidth=softWidth
let &l:expandtab=1
endfun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment