Fixed vim and zsh
This commit is contained in:
1
vim/plugins/vim-better-whitespace/.gitignore
vendored
Normal file
1
vim/plugins/vim-better-whitespace/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
doc/tags
|
241
vim/plugins/vim-better-whitespace/README.md
Normal file
241
vim/plugins/vim-better-whitespace/README.md
Normal file
@ -0,0 +1,241 @@
|
||||
#Vim Better Whitespace Plugin
|
||||
|
||||
This plugin causes all trailing whitespace characters (see [Supported Whitespace Characters](#supported-whitespace-characters) below) to be
|
||||
highlighted. Whitespace for the current line will not be highlighted
|
||||
while in insert mode. It is possible to disable current line highlighting while in other
|
||||
modes as well (see options below). A helper function `:StripWhitespace` is also provided
|
||||
to make whitespace cleaning painless.
|
||||
|
||||
Here is a screenshot of this plugin at work:
|
||||

|
||||
|
||||
##Installation
|
||||
There are a few ways you can go about installing this plugin:
|
||||
|
||||
1. If you have [Vundle](https://github.com/gmarik/Vundle.vim) you can simply add:
|
||||
```
|
||||
Plugin 'ntpeters/vim-better-whitespace'
|
||||
```
|
||||
to your `.vimrc` file then run:
|
||||
```
|
||||
:PluginInstall
|
||||
```
|
||||
2. If you are using [Pathogen](https://github.com/tpope/vim-pathogen), you can just run the following command:
|
||||
```
|
||||
git clone git://github.com/ntpeters/vim-better-whitespace.git ~/.vim/bundle/vim-better-whitespace
|
||||
```
|
||||
3. While this plugin can also be installed by copying its contents into your `~/.vim/` directory, I would highly recommend using one of the above methods as they make managing your Vim plugins painless.
|
||||
|
||||
##Usage
|
||||
Whitespace highlighting is enabled by default, with a highlight color of red.
|
||||
|
||||
* To set a custom highlight color, just call:
|
||||
```
|
||||
highlight ExtraWhitespace ctermbg=<desired_color>
|
||||
```
|
||||
|
||||
* To toggle whitespace highlighting on/off, call:
|
||||
```
|
||||
:ToggleWhitespace
|
||||
```
|
||||
|
||||
* To disable highlighting for the current line in normal mode call:
|
||||
```
|
||||
:CurrentLineWhitespaceOff <level>
|
||||
```
|
||||
Where `<level>` is either `hard` or `soft`.
|
||||
|
||||
* The level `hard` will maintain whitespace highlighting as it is, but may
|
||||
cause a slow down in Vim since it uses the CursorMoved event to detect and
|
||||
exclude the current line.
|
||||
|
||||
* The level `soft` will use syntax based highlighting, so there shouldn't be
|
||||
a performance hit like with the `hard` option. The drawback is that this
|
||||
highlighting will have a lower priority and may be overwritten by higher
|
||||
priority highlighting.
|
||||
|
||||
* To re-enable highlighting for the current line in normal mode:
|
||||
```
|
||||
:CurrentLineWhitespaceOn
|
||||
```
|
||||
|
||||
* To clean extra whitespace, call:
|
||||
```
|
||||
:StripWhitespace
|
||||
```
|
||||
By default this operates on the entire file. To restrict the portion of
|
||||
the file that it cleans, either give it a range or select a group of lines
|
||||
in visual mode and then execute it.
|
||||
|
||||
* To enable/disable stripping of extra whitespace on file save, call:
|
||||
```
|
||||
:ToggleStripWhitespaceOnSave
|
||||
```
|
||||
This will strip all trailing whitespace everytime you save the file for all file types.
|
||||
|
||||
* If you want this behaviour by default for all filetypes, add the following to your `~/.vimrc`:
|
||||
|
||||
```
|
||||
autocmd BufEnter * EnableStripWhitespaceOnSave
|
||||
```
|
||||
|
||||
For exceptions of all see ```g:better_whitespace_filetypes_blacklist```.
|
||||
|
||||
* If you would prefer to only strip whitespace for certain filetypes, add
|
||||
the following to your `~/.vimrc`:
|
||||
|
||||
```
|
||||
autocmd FileType <desired_filetypes> autocmd BufEnter <buffer> EnableStripWhitespaceOnSave
|
||||
```
|
||||
|
||||
where `<desired_filetypes>` is a comma separated list of the file types you want
|
||||
to be stripped of whitespace on file save ( ie. `javascript,c,cpp,java,html,ruby` )
|
||||
Note that `<buffer>` is a keyword here denoting operation on the current buffer and
|
||||
should stay just as it appears in the line above.
|
||||
|
||||
* To disable this plugin for specific file types, add the following to your `~/.vimrc`:
|
||||
```
|
||||
let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>']
|
||||
```
|
||||
This replaces the filetypes from the default list of blacklisted filetypes. The
|
||||
default types that are blacklisted are:
|
||||
```
|
||||
['diff', 'gitcommit', 'unite', 'qf', 'help', 'markdown']
|
||||
```
|
||||
If you do not want any of these filetypes unignored, simply include them in the
|
||||
blacklist:
|
||||
```
|
||||
let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>',
|
||||
'diff', 'gitcommit', 'unite', 'qf', 'help']
|
||||
```
|
||||
|
||||
* To enable verbose output for each command, set verbosity in your `.vimrc`:
|
||||
```
|
||||
let g:better_whitespace_verbosity=1
|
||||
```
|
||||
|
||||
##Supported Whitespace Characters
|
||||
Due to the fact that the built-in whitespace character class for patterns (`\s`)
|
||||
only matches against tabs and spaces, this plugin defines its own list of
|
||||
horizontal whitepsace characters to match for both highlighting and stripping.
|
||||
|
||||
This is list should match against all ASCII and Unicode horizontal whitespace
|
||||
characters:
|
||||
```
|
||||
U+0009 TAB
|
||||
U+0020 SPACE
|
||||
U+00A0 NO-BREAK SPACE
|
||||
U+1680 OGHAM SPACE MARK
|
||||
U+180E MONGOLIAN VOWEL SEPARATOR
|
||||
U+2000 EN QUAD
|
||||
U+2001 EM QUAD
|
||||
U+2002 EN SPACE
|
||||
U+2003 EM SPACE
|
||||
U+2004 THREE-PER-EM SPACE
|
||||
U+2005 FOUR-PER-EM SPACE
|
||||
U+2006 SIX-PER-EM SPACE
|
||||
U+2007 FIGURE SPACE
|
||||
U+2008 PUNCTUATION SPACE
|
||||
U+2009 THIN SPACE
|
||||
U+200A HAIR SPACE
|
||||
U+200B ZERO WIDTH SPACE
|
||||
U+202F NARROW NO-BREAK SPACE
|
||||
U+205F MEDIUM MATHEMATICAL SPACE
|
||||
U+3000 IDEOGRAPHIC SPACE
|
||||
U+FEFF ZERO WIDTH NO-BREAK SPACE
|
||||
```
|
||||
|
||||
A file is provided with samples of each of these characters to check the plugin
|
||||
working with them: whitespace_examples.txt
|
||||
|
||||
If you encounter any additional whitespace characters I have missed here,
|
||||
please submit a pull request.
|
||||
|
||||
##Screenshots
|
||||
Here are a couple more screenshots of the plugin at work.
|
||||
|
||||
This screenshot shows the current line not being highlighted in insert mode:
|
||||

|
||||
|
||||
This screenshot shows the current line not being highlighted in normal mode( `CurrentLineWhitespaceOff hard` ):
|
||||

|
||||
|
||||
This screenshot shows that highlighting works fine for spaces, tabs, and a mixture of both:
|
||||

|
||||
|
||||
##Frequently Asked Questions
|
||||
Hopefully some of the most common questions will be answered here. If you still have a question
|
||||
that I have failed to address, please open an issue and ask it!
|
||||
|
||||
**Q: Why is trailing whitespace such a big deal?**
|
||||
|
||||
A: In most cases it is not a syntactical issue, but rather is a common annoyance among
|
||||
programmers.
|
||||
|
||||
|
||||
**Q: Why not just use `listchars` with `SpecialKey` highlighting?**
|
||||
|
||||
A: I tried using `listchars` to show trail characters with `SpecialKey` highlighting applied.
|
||||
Using this method the characters would still show on the current line for me even when the
|
||||
`SpecialKey` foreground highlight matched the `CursorLine` background highlight.
|
||||
|
||||
|
||||
**Q: Okay, so `listchars` doesn't do exactly what you want, why not just use a `match` in your `vimrc`?**
|
||||
|
||||
A: I am using `match` in this plugin, but I've also added a way to exclude the current line in
|
||||
insert mode and/or normal mode.
|
||||
|
||||
|
||||
**Q: If you just want to exclude the current line, why not just use syntax-based highlight rather
|
||||
than using `match` and `CursorMoved` events?**
|
||||
|
||||
A: Syntax-based highlighting is an option in this plugin. It is used to omit the current line when
|
||||
using `CurrentLineWhitespaceOff soft`. The only issue with this method is that `match` highlighing
|
||||
takes higher priorty than syntax highlighting. For example, when using a plugin such as
|
||||
[Indent Guides](https://github.com/nathanaelkane/vim-indent-guides), syntax-based highlighting of
|
||||
extra whitespace will not highlight additional white space on emtpy lines.
|
||||
|
||||
|
||||
**Q: I already have my own method of removing white space, why is the method used in this plugin better?**
|
||||
|
||||
A: It may not be, depending on the method you are using. The method used in this plugin strips extra
|
||||
white space and then restores the cursor position and last search history.
|
||||
|
||||
|
||||
**Q: Most of this is pretty easy to just add to users' `vimrc` files. Why make it a plugin?**
|
||||
|
||||
A: It is true that a large part of this is fairly simple to make a part of an individuals
|
||||
configuration in their `vimrc`. I wanted to provide something that is easy to setup and use
|
||||
for both those new to Vim and others who don't want to mess around setting up this
|
||||
functionality in their `vimrc`.
|
||||
|
||||
**Q: Can you add indentation highlighting for spaces/tabs? Can you add highlighting for other
|
||||
types of white space?**
|
||||
|
||||
A: No, and no. Sorry, but both are outside the scope of this plugin. The purpose of this plugin
|
||||
is to provide a better experience for showing and dealing with extra white space. There is
|
||||
already an amazing plugin for showing indentation in Vim called [Indent Guides](https://github.com/nathanaelkane/vim-indent-guides).
|
||||
For other types of white space highlighting, [listchars](http://vimdoc.sourceforge.net/htmldoc/options.html#'listchars') should be sufficient.
|
||||
|
||||
**Q: I have a better way to do something in this plugin. OR You're doing something stupid/wrong/bad.**
|
||||
|
||||
A: If you know of a better way to do something I am attempting in this plugin, or if I am doing
|
||||
something improperly/not reccomended then let me know! Please either open an issue informing
|
||||
me or make the changes yourself and open a pull request. If I am doing something that is bad
|
||||
or can be improved, I more than willing to hear about it!
|
||||
|
||||
##Promotion
|
||||
If you like this plugin, please star it on Github and vote it up at Vim.org!
|
||||
|
||||
Repository exists at: http://github.com/ntpeters/vim-better-whitespace
|
||||
|
||||
Plugin also hosted at: http://www.vim.org/scripts/script.php?script_id=4859
|
||||
|
||||
##Credits
|
||||
Originally inspired by: https://github.com/bronson/vim-trailing-whitespace
|
||||
|
||||
Based on:
|
||||
|
||||
http://sartak.org/2011/03/end-of-line-whitespace-in-vim.html
|
||||
|
||||
http://vim.wikia.com/wiki/Highlight_unwanted_spaces
|
65
vim/plugins/vim-better-whitespace/doc/better-whitespace.txt
Normal file
65
vim/plugins/vim-better-whitespace/doc/better-whitespace.txt
Normal file
@ -0,0 +1,65 @@
|
||||
*better-whitespace.txt* better-whitespace
|
||||
|
||||
|
||||
This plugin causes all trailing whitespace characters (spaces and tabs) to be
|
||||
highlighted. Whitespace for the current line will not be highlighted while in
|
||||
insert mode. It is possible to disable current line highlighting while in other
|
||||
modes as well (see options below).
|
||||
|
||||
To blacklist certain filetypes, set 'g:better_whitespace_filetypes_blacklist'
|
||||
to a list of the desired filetypes.
|
||||
|
||||
|
||||
*ToggleWhitespace*
|
||||
|
||||
Call :ToggleWhitespace to toggle whitespace highlighting on/off.
|
||||
|
||||
*EnableWhitespace*
|
||||
|
||||
To enable whitespace highlighting, call :EnableWhitespace. This will enable
|
||||
highlighting of extraneous whitespace for the entire file.
|
||||
|
||||
*DisableWhitespace*
|
||||
|
||||
To disable whitespace highlighting, call :DisableWhitespace. This will disable
|
||||
highlighting of extraneous whitespace for the entire file.
|
||||
|
||||
*StripWhitespace*
|
||||
|
||||
To remove extra whitespace, just call :StripWhitespace.By default this
|
||||
operates on the entire file. To restrict the portion of the file that it
|
||||
cleans, either give it a range or select a group of lines in visual mode
|
||||
and then execute it.
|
||||
|
||||
*ToggleStripWhitespaceOnSave*
|
||||
|
||||
This enables/disables stripping of extra whitespace on file save.
|
||||
|
||||
*CurrentLineWhitespaceOff*
|
||||
|
||||
Calling :CurrentLineWhitespaceOff with the option either 'hard' or 'soft' will
|
||||
disable whitespace highlighting for the currentline.
|
||||
|
||||
If 'hard' option is used, then all highlighting remains the same except that
|
||||
the current line is not highlighted.
|
||||
WARNING: Since this uses CursorMoved events to prevent highlighting of the
|
||||
current line there is a chance this can cause a significant slow down of Vim,
|
||||
especially with regard to large files.
|
||||
|
||||
If the 'soft' option is used, then highlighting will have a lower priority
|
||||
potentially causing this highlighting to be overwritten by other, higher
|
||||
priority highlighting. The benefit is that there should be no slowdown with
|
||||
this option.
|
||||
|
||||
*CurrentLineWhitespaceOn
|
||||
|
||||
Call :CurrentLineWhitespaceOn to enable whitespace highlighting for the current
|
||||
line. Highlighting is still disabled for the current line while in inserte mode.
|
||||
|
||||
Repository exists at: http://github.com/ntpeters/vim-better-whitespace
|
||||
|
||||
Originally inspired by: https://github.com/bronson/vim-trailing-whitespace
|
||||
|
||||
Based on:
|
||||
http://sartak.org/2011/03/end-of-line-whitespace-in-vim.html
|
||||
http://vim.wikia.com/wiki/Highlight_unwanted_spaces
|
295
vim/plugins/vim-better-whitespace/plugin/better-whitespace.vim
Normal file
295
vim/plugins/vim-better-whitespace/plugin/better-whitespace.vim
Normal file
@ -0,0 +1,295 @@
|
||||
" Author: Nate Peterson
|
||||
" Repository: https://github.com/ntpeters/vim-better-whitespace
|
||||
|
||||
" Prevent loading the plugin multiple times
|
||||
if exists('g:loaded_better_whitespace_plugin')
|
||||
finish
|
||||
endif
|
||||
let g:loaded_better_whitespace_plugin = 1
|
||||
|
||||
" Initializes a given variable to a given value. The variable is only
|
||||
" initialized if it does not exist prior.
|
||||
function! s:InitVariable(var, value)
|
||||
if !exists(a:var)
|
||||
execute 'let ' . a:var . ' = ' . string(a:value)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Set this to enable/disable whitespace highlighting
|
||||
call s:InitVariable('g:better_whitespace_enabled', 1)
|
||||
|
||||
" Set this to disable highlighting on the current line in all modes
|
||||
" WARNING: This checks for current line on cursor move, which can significantly
|
||||
" impact the performance of Vim (especially on large files)
|
||||
call s:InitVariable('g:current_line_whitespace_disabled_hard', 0)
|
||||
|
||||
" Set this to disable highlighting of the current line in all modes
|
||||
" This setting will not have the performance impact of the above, but
|
||||
" highlighting throughout the file may be overridden by other highlight
|
||||
" patterns with higher priority.
|
||||
call s:InitVariable('g:current_line_whitespace_disabled_soft', 0)
|
||||
|
||||
" Set this to enable stripping whitespace on file save
|
||||
call s:InitVariable('g:strip_whitespace_on_save', 0)
|
||||
|
||||
" Set this to blacklist specific filetypes
|
||||
let default_blacklist=['diff', 'gitcommit', 'unite', 'qf', 'help', 'markdown']
|
||||
call s:InitVariable('g:better_whitespace_filetypes_blacklist', default_blacklist)
|
||||
|
||||
" Disable verbosity by default
|
||||
call s:InitVariable('g:better_whitespace_verbosity', 0)
|
||||
|
||||
" Define custom whitespace character group to include all horizontal unicode
|
||||
" whitespace characters. Vim's '\s' class only includes ASCII spaces and tabs.
|
||||
let s:whitespace_group='[\u0009\u0020\u00a0\u1680\u180e\u2000-\u200b\u202f\u205f\u3000\ufeff]'
|
||||
let s:eol_whitespace_pattern = s:whitespace_group . '\+$'
|
||||
|
||||
" Only init once
|
||||
let s:better_whitespace_initialized = 0
|
||||
|
||||
" Like windo but restore the current window.
|
||||
function! s:Windo(command)
|
||||
let currwin=winnr()
|
||||
execute 'windo ' . a:command
|
||||
execute currwin . 'wincmd w'
|
||||
endfunction
|
||||
|
||||
" Like tabdo but restore the current tab.
|
||||
function! s:Tabdo(command)
|
||||
let currTab=tabpagenr()
|
||||
execute 'tabdo ' . a:command
|
||||
execute 'tabn ' . currTab
|
||||
endfunction
|
||||
|
||||
" Execute command in all windows (across tabs).
|
||||
function! s:InAllWindows(command)
|
||||
call s:Tabdo("call s:Windo('".substitute(a:command, "'", "''", 'g')."')")
|
||||
endfunction
|
||||
|
||||
" Ensure the 'ExtraWhitespace' highlight group has been defined
|
||||
function! s:WhitespaceInit()
|
||||
" Check if the user has already defined highlighting for this group
|
||||
if hlexists("ExtraWhitespace") == 0 || synIDattr(synIDtrans(hlID("ExtraWhitespace")), "bg") == -1
|
||||
highlight ExtraWhitespace ctermbg = red guibg = #FF0000
|
||||
endif
|
||||
let s:better_whitespace_initialized = 1
|
||||
endfunction
|
||||
|
||||
" Like 'echo', but only outputs the message when verbosity is enabled
|
||||
function! s:Echo(message)
|
||||
if g:better_whitespace_verbosity == 1
|
||||
echo a:message
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Enable the whitespace highlighting
|
||||
function! s:EnableWhitespace()
|
||||
if b:better_whitespace_enabled == 0
|
||||
let b:better_whitespace_enabled = 1
|
||||
call <SID>WhitespaceInit()
|
||||
call <SID>SetupAutoCommands()
|
||||
call <SID>Echo("Whitespace Highlighting: Enabled")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Disable the whitespace highlighting
|
||||
function! s:DisableWhitespace()
|
||||
if b:better_whitespace_enabled == 1
|
||||
let b:better_whitespace_enabled = 0
|
||||
call <SID>SetupAutoCommands()
|
||||
call <SID>Echo("Whitespace Highlighting: Disabled")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Toggle whitespace highlighting on/off
|
||||
function! s:ToggleWhitespace()
|
||||
if b:better_whitespace_enabled == 1
|
||||
call <SID>DisableWhitespace()
|
||||
else
|
||||
call <SID>EnableWhitespace()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" This disabled whitespace highlighting on the current line in all modes
|
||||
" Options:
|
||||
" hard - Disables highlighting for current line and maintains high priority
|
||||
" highlighting for the entire file. Caution: may cause slowdown in Vim!
|
||||
" soft - No potential slowdown as with 'hard' option, but other highlighting
|
||||
" rules of higher priority may overwrite these whitespace highlights.
|
||||
function! s:CurrentLineWhitespaceOff( level )
|
||||
if g:better_whitespace_enabled == 1
|
||||
" Set current line whitespace level
|
||||
if a:level == 'hard'
|
||||
let g:current_line_whitespace_disabled_hard = 1
|
||||
let g:current_line_whitespace_disabled_soft = 0
|
||||
call s:InAllWindows('syn clear ExtraWhitespace | match ExtraWhitespace "' . s:eol_whitespace_pattern . '"')
|
||||
call <SID>Echo("Current Line Hightlight Off (hard)")
|
||||
elseif a:level == 'soft'
|
||||
let g:current_line_whitespace_disabled_soft = 1
|
||||
let g:current_line_whitespace_disabled_hard = 0
|
||||
call s:InAllWindows("match ExtraWhitespace ''")
|
||||
call <SID>Echo("Current Line Hightlight Off (soft)")
|
||||
endif
|
||||
" Re-run auto commands with the new settings
|
||||
call <SID>SetupAutoCommands()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Enables whitespace highlighting for the current line
|
||||
function! s:CurrentLineWhitespaceOn()
|
||||
if g:better_whitespace_enabled == 1
|
||||
let g:current_line_whitespace_disabled_hard = 0
|
||||
let g:current_line_whitespace_disabled_soft = 0
|
||||
call <SID>SetupAutoCommands()
|
||||
call s:InAllWindows('syn clear ExtraWhitespace | match ExtraWhitespace "' . s:eol_whitespace_pattern . '"')
|
||||
call <SID>Echo("Current Line Hightlight On")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Removes all extraneous whitespace in the file
|
||||
function! s:StripWhitespace( line1, line2 )
|
||||
" Save the current search and cursor position
|
||||
let _s=@/
|
||||
let l = line(".")
|
||||
let c = col(".")
|
||||
|
||||
" Strip the whitespace
|
||||
silent! execute ':' . a:line1 . ',' . a:line2 . 's/' . s:eol_whitespace_pattern . '//e'
|
||||
|
||||
" Restore the saved search and cursor position
|
||||
let @/=_s
|
||||
call cursor(l, c)
|
||||
endfunction
|
||||
|
||||
" Strip whitespace on file save
|
||||
function! s:EnableStripWhitespaceOnSave()
|
||||
let g:strip_whitespace_on_save = 1
|
||||
call <SID>Echo("Strip Whitespace On Save: Enabled")
|
||||
call <SID>SetupAutoCommands()
|
||||
endfunction
|
||||
|
||||
" Don't strip whitespace on file save
|
||||
function! s:DisableStripWhitespaceOnSave()
|
||||
let g:strip_whitespace_on_save = 0
|
||||
call <SID>Echo("Strip Whitespace On Save: Disabled")
|
||||
call <SID>SetupAutoCommands()
|
||||
endfunction
|
||||
|
||||
" Strips whitespace on file save
|
||||
function! s:ToggleStripWhitespaceOnSave()
|
||||
if g:strip_whitespace_on_save == 1
|
||||
call <SID>DisableStripWhitespaceOnSave()
|
||||
else
|
||||
call <SID>EnableStripWhitespaceOnSave()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Determines if whitespace highlighting should currently be skipped
|
||||
function! s:ShouldSkipHighlight()
|
||||
return &buftype == 'nofile' || index(g:better_whitespace_filetypes_blacklist, &ft) >= 0
|
||||
endfunction
|
||||
|
||||
" Run :StripWhitespace to remove end of line whitespace
|
||||
command! -range=% StripWhitespace call <SID>StripWhitespace( <line1>, <line2> )
|
||||
" Run :EnableStripWhitespaceOnSave to enable whitespace stripping on save
|
||||
command! EnableStripWhitespaceOnSave call <SID>EnableStripWhitespaceOnSave()
|
||||
" Run :DisableStripWhitespaceOnSave to disable whitespace stripping on save
|
||||
command! DisableStripWhitespaceOnSave call <SID>DisableStripWhitespaceOnSave()
|
||||
" Run :ToggleStripWhitespaceOnSave to enable/disable whitespace stripping on save
|
||||
command! ToggleStripWhitespaceOnSave call <SID>ToggleStripWhitespaceOnSave()
|
||||
" Run :EnableWhitespace to enable whitespace highlighting
|
||||
command! EnableWhitespace call <SID>EnableWhitespace()
|
||||
" Run :DisableWhitespace to disable whitespace highlighting
|
||||
command! DisableWhitespace call <SID>DisableWhitespace()
|
||||
" Run :ToggleWhitespace to toggle whitespace highlighting on/off
|
||||
command! ToggleWhitespace call <SID>ToggleWhitespace()
|
||||
" Run :CurrentLineWhitespaceOff(level) to disable highlighting for the current
|
||||
" line. Levels are: 'hard' and 'soft'
|
||||
command! -nargs=* CurrentLineWhitespaceOff call <SID>CurrentLineWhitespaceOff( <f-args> )
|
||||
" Run :CurrentLineWhitespaceOn to turn on whitespace for the current line
|
||||
command! CurrentLineWhitespaceOn call <SID>CurrentLineWhitespaceOn()
|
||||
|
||||
" Process auto commands upon load, update local enabled on filetype change
|
||||
autocmd FileType * let b:better_whitespace_enabled = !<SID>ShouldSkipHighlight() | call <SID>SetupAutoCommands()
|
||||
autocmd WinEnter,BufWinEnter * call <SID>SetupAutoCommands()
|
||||
autocmd ColorScheme * call <SID>WhitespaceInit()
|
||||
|
||||
function! s:PerformMatchHighlight(pattern)
|
||||
call s:InitVariable('b:better_whitespace_enabled', !<SID>ShouldSkipHighlight())
|
||||
if b:better_whitespace_enabled == 1
|
||||
exe 'match ExtraWhitespace "' . a:pattern . '"'
|
||||
else
|
||||
match ExtraWhitespace ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:PerformSyntaxHighlight(pattern)
|
||||
syn clear ExtraWhitespace
|
||||
call s:InitVariable('b:better_whitespace_enabled', !<SID>ShouldSkipHighlight())
|
||||
if b:better_whitespace_enabled == 1
|
||||
exe 'syn match ExtraWhitespace excludenl "' . a:pattern . '"'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HighlightEOLWhitespace(type)
|
||||
if (a:type == 'match')
|
||||
call s:PerformMatchHighlight(s:eol_whitespace_pattern)
|
||||
elseif (a:type == 'syntax')
|
||||
call s:PerformSyntaxHighlight(s:eol_whitespace_pattern)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HighlightEOLWhitespaceExceptCurrentLine(type)
|
||||
let a:exclude_current_line_eol_whitespace_pattern = '\%<' . line(".") . 'l' . s:eol_whitespace_pattern . '\|\%>' . line(".") . 'l' . s:eol_whitespace_pattern
|
||||
if (a:type == 'match')
|
||||
call s:PerformMatchHighlight(a:exclude_current_line_eol_whitespace_pattern)
|
||||
elseif (a:type == 'syntax')
|
||||
call s:PerformSyntaxHighlight(a:exclude_current_line_eol_whitespace_pattern)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Executes all auto commands
|
||||
function! <SID>SetupAutoCommands()
|
||||
" Auto commands group
|
||||
augroup better_whitespace
|
||||
autocmd!
|
||||
|
||||
if g:better_whitespace_enabled == 1
|
||||
if s:better_whitespace_initialized == 0
|
||||
call <SID>WhitespaceInit()
|
||||
endif
|
||||
|
||||
|
||||
" Check if current line is disabled softly
|
||||
if g:current_line_whitespace_disabled_soft == 0
|
||||
" Highlight all whitespace upon entering buffer
|
||||
call <SID>PerformMatchHighlight(s:eol_whitespace_pattern)
|
||||
" Check if current line highglighting is disabled
|
||||
if g:current_line_whitespace_disabled_hard == 1
|
||||
" Never highlight whitespace on current line
|
||||
autocmd InsertEnter,CursorMoved,CursorMovedI * call <SID>HighlightEOLWhitespaceExceptCurrentLine('match')
|
||||
else
|
||||
" When in insert mode, do not highlight whitespace on the current line
|
||||
autocmd InsertEnter,CursorMovedI * call <SID>HighlightEOLWhitespaceExceptCurrentLine('match')
|
||||
endif
|
||||
" Highlight all whitespace when exiting insert mode
|
||||
autocmd InsertLeave,BufReadPost * call <SID>HighlightEOLWhitespace('match')
|
||||
" Clear whitespace highlighting when leaving buffer
|
||||
autocmd BufWinLeave * match ExtraWhitespace ''
|
||||
else
|
||||
" Highlight extraneous whitespace at the end of lines, but not the
|
||||
" current line.
|
||||
call <SID>HighlightEOLWhitespace('syntax')
|
||||
autocmd InsertEnter * call <SID>HighlightEOLWhitespaceExceptCurrentLine('syntax')
|
||||
autocmd InsertLeave,BufReadPost * call <SID>HighlightEOLWhitespace('syntax')
|
||||
endif
|
||||
endif
|
||||
|
||||
" Strip whitespace on save if enabled
|
||||
if g:strip_whitespace_on_save == 1
|
||||
autocmd BufWritePre * call <SID>StripWhitespace( 0, line("$") )
|
||||
endif
|
||||
|
||||
augroup END
|
||||
endfunction
|
||||
|
21
vim/plugins/vim-better-whitespace/whitespace_examples.txt
Normal file
21
vim/plugins/vim-better-whitespace/whitespace_examples.txt
Normal file
@ -0,0 +1,21 @@
|
||||
U+0009 TAB:
|
||||
U+0020 SPACE:
|
||||
U+00A0 NO-BREAK SPACE:
|
||||
U+1680 OGHAM SPACE MARK:
|
||||
U+180E MONGOLIAN VOWEL SEPARATOR:
|
||||
U+2000 EN QUAD:
|
||||
U+2001 EM QUAD:
|
||||
U+2002 EN SPACE:
|
||||
U+2003 EM SPACE:
|
||||
U+2004 THREE-PER-EM SPACE:
|
||||
U+2005 FOUR-PER-EM SPACE:
|
||||
U+2006 SIX-PER-EM SPACE:
|
||||
U+2007 FIGURE SPACE:
|
||||
U+2008 PUNCTUATION SPACE:
|
||||
U+2009 THIN SPACE:
|
||||
U+200A HAIR SPACE:
|
||||
U+200B ZERO WIDTH SPACE:
|
||||
U+202F NARROW NO-BREAK SPACE:
|
||||
U+205F MEDIUM MATHEMATICAL SPACE:
|
||||
U+3000 IDEOGRAPHIC SPACE:
|
||||
U+FEFF ZERO WIDTH NO-BREAK SPACE:
|
Reference in New Issue
Block a user