Skip to content

Instantly share code, notes, and snippets.

@rgngl
Created February 5, 2010 08:49
Show Gist options
  • Save rgngl/295650 to your computer and use it in GitHub Desktop.
Save rgngl/295650 to your computer and use it in GitHub Desktop.
"Trailing whitespace stuff
function ShowSpaces(...)
let @/="\\v(\\s+$)|( +\\ze\\t)"
let oldhlsearch=&hlsearch
if !a:0
let &hlsearch=!&hlsearch
else
let &hlsearch=a:1
end
return oldhlsearch
endfunction
function TrimSpaces() range
let oldhlsearch=ShowSpaces(1)
execute a:firstline.",".a:lastline."substitute ///gec"
let &hlsearch=oldhlsearch
endfunction
command -bar -nargs=? ShowSpaces call ShowSpaces(<args>)
command -bar -nargs=0 -range=% TrimSpaces <line1>,<line2>call TrimSpaces()
nnoremap <F6> :ShowSpaces 1<CR>
nnoremap <S-F6> m`:TrimSpaces<CR>``
vnoremap <S-F6> :TrimSpaces<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment