Skip to content
Browse files

some fixes to retab logic

  • Loading branch information...
1 parent 07765b3 commit 6e8766eb5cf6ad105638b59cccd349c9285abce0 @cengebretson committed Apr 1, 2013
Showing with 18 additions and 7 deletions.
  1. +18 −7 vimrc
View
25 vimrc
@@ -91,10 +91,10 @@ set autoindent " indent at the same level of th
" Tabs "
"------------"
-set shiftwidth=2 " use indents of 4 spaces
-set expandtab " tabs are spaces
-set tabstop=2 " an indentation every four columns
+set shiftwidth=4 " use indents of 4 spaces
+set tabstop=4 " an indentation every four columns
set softtabstop=2 " let backspace delete indent
+set expandtab " tabs are spaces
@@ -108,10 +108,11 @@ set softtabstop=2 " let backspace delete indent
autocmd! FileType * setlocal formatoptions-=r
" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ )
-autocmd FileType python setlocal softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79 expandtab
+autocmd FileType python setlocal sts=4 ts=4 sw=4 tw=79 et
" javascript file type settings
autocmd FileType javascript setlocal sw=2 sts=2 ts=2 et
+autocmd FileType coffee setlocal sw=2 sts=2 ts=2 et
" Automatically go to relative number when using insert mode
autocmd InsertEnter * set number
@@ -246,8 +247,8 @@ imap <silent> <c-p> <esc> :call FindProjectRoot()<CR><Plug>PeepOpen
nmap <silent> <leader>tt :call TabToggle()<cr>
" mapping to use a different tab setting more suitable for other languages
-nmap <silent> <leader>t2 :setlocal softtabstop=2 tabstop=2 shiftwidth=2<CR>:retab!<cr>
-nmap <silent> <leader>t4 :setlocal softtabstop=4 tabstop=4 shiftwidth=4<CR>:retab!<cr>
+nmap <silent> <leader>t2 :setlocal softtabstop=2 tabstop=2 shiftwidth=2<CR>:call NiceRetab()<cr>
+nmap <silent> <leader>t4 :setlocal softtabstop=4 tabstop=4 shiftwidth=4<CR>:call NiceRetab()<cr>
" open up the current file's directory in finder
nmap <silent> <leader>o :lcd %:h<CR>:! open .<cr><cr>
@@ -493,7 +494,7 @@ endfunction
function! TabToggle()
let l:winview = winsaveview()
- if(&expandtab > 0)
+ if (&expandtab > 0)
Space2Tab
else
Tab2Space
@@ -502,6 +503,16 @@ function! TabToggle()
call winrestview(l:winview)
endfunc
+function! NiceRetab()
+ let l:winview = winsaveview()
+ if (&expandtab == 0)
+ Space2Tab
+ else
+ Tab2Space
+ endif
+ call winrestview(l:winview)
+endfunc
+
command! -range=% -nargs=0 Tab2Space exec "silent! <line1>,<line2>s/^\\t\\+/\\=substitute(submatch(0), '\\t',repeat(' ', ".&ts."), 'g')"
command! -range=% -nargs=0 Space2Tab exec "silent! <line1>,<line2>s/^\\( \\{".&ts."\\}\\)\\+/\\=substitute(submatch(0), ' \\{".&ts."\\}','\\t', 'g')"

0 comments on commit 6e8766e

Please sign in to comment.
Something went wrong with that request. Please try again.