Skip to content

Instantly share code, notes, and snippets.

@tavisto
Last active August 29, 2015 13:56
Show Gist options
  • Save tavisto/9080826 to your computer and use it in GitHub Desktop.
Save tavisto/9080826 to your computer and use it in GitHub Desktop.
Add some commands to fix whitespace issues.
" Make all tabs 4 spaces
" Make tabs delete properly
" Make autoindent add 4 spaces per indent level
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab " Convert all tabs
set smarttab
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap <leader>$ :call Preserve("%s/\\s\\+$//e")<CR>
nmap <leader>= :call Preserve("normal gg=G")<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment