├── .gitignore ├── README ├── doc └── trailing-whitespace.txt └── plugin └── trailing-whitespace.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This plugin causes trailing whitespace to be highlighted in red. 2 | 3 | To fix the whitespace errors, call :FixWhitespace. By default it 4 | operates on the entire file. Pass a range (or use V to select some lines) 5 | to restrict the portion of the file that gets fixed. 6 | 7 | The repo is at http://github.com/bronson/vim-trailing-whitespace 8 | 9 | Originally based on http://vim.wikia.com/wiki/Highlight_unwanted_spaces 10 | 11 | License: cc-by-sa. The instructions this plugin is based on were 12 | licensed cc-by-sa so, until a reason to force a different license appears, 13 | we'll continue to use it. 14 | 15 | A more complete alternative is at https://github.com/ntpeters/vim-better-whitespace 16 | -------------------------------------------------------------------------------- /doc/trailing-whitespace.txt: -------------------------------------------------------------------------------- 1 | *trailing-whitespace.txt* trailing-whitespace 2 | 3 | 4 | This plugin causes all trailing whitespace to be highlighted in red. 5 | 6 | 7 | *FixWhitespace* 8 | 9 | To fix the whitespace errors, just call :FixWhitespace. By default it 10 | operates on the entire file. Pass a range (or use V to select some lines) 11 | to restrict the portion of the file that gets fixed. 12 | 13 | The repo is at http://github.com/bronson/vim-trailing-whitespace 14 | 15 | Originally based on http://vim.wikia.com/wiki/Highlight_unwanted_spaces 16 | 17 | ------------------------------------------------------------------------------ 18 | VARIABLES *FixWhitespace-variables* 19 | 20 | g:extra_whitespace_ignored_filetypes 21 | g:extra_whitespace_ignored_filetypes 22 | You can set filetypes to be ignored for highlight into this variable. 23 | 24 | let g:extra_whitespace_ignored_filetypes = ['unite', 'mkd'] 25 | 26 | The default value is []. 27 | -------------------------------------------------------------------------------- /plugin/trailing-whitespace.vim: -------------------------------------------------------------------------------- 1 | if exists('loaded_trailing_whitespace_plugin') | finish | endif 2 | let loaded_trailing_whitespace_plugin = 1 3 | 4 | if !exists('g:extra_whitespace_ignored_filetypes') 5 | let g:extra_whitespace_ignored_filetypes = [] 6 | endif 7 | 8 | function! ShouldMatchWhitespace() 9 | for ft in g:extra_whitespace_ignored_filetypes 10 | if ft ==# &filetype | return 0 | endif 11 | endfor 12 | if &buftype ==# 'terminal' | return 0 | endif 13 | return 1 14 | endfunction 15 | 16 | " Highlight EOL whitespace, http://vim.wikia.com/wiki/Highlight_unwanted_spaces 17 | highlight default ExtraWhitespace ctermbg=darkred guibg=darkred 18 | autocmd ColorScheme * highlight default ExtraWhitespace ctermbg=darkred guibg=darkred 19 | let term_open_event = (has('nvim') ? 'TermOpen' : 'TerminalOpen') 20 | exe 'autocmd BufRead,BufNew,FileType,' term_open_event '* if ShouldMatchWhitespace() | match ExtraWhitespace /\\\@FixWhitespace(,) 32 | --------------------------------------------------------------------------------