bronson / vim-trailing-whitespace

Highlights trailing whitespace in red and provides :FixWhitespace to fix it.
453 stars 62 forks source link

Stop the script from double execution with a "loaded" variable #3

Closed ghost closed 11 years ago

ghost commented 11 years ago

By adding these two lines to the top of the file:

if exists('loaded_trailing_whitespace_plugin') | finish | endif
let loaded_trailing_whitespace_plugin = 1

this will stop the script from executing twice if it is, for some reason, loaded twice.

If you look around Github, you will find that it is convention for scripts to do this.

The variable also lets users disable the plugin under certain circumstances, for example I don't want the plugin to run in emails, so after this is merged I will be able to put in my .vimrc:

autocmd filetype mail let loaded_trailing_whitespace_plugin = 1

and the plugin won't run in email files.

bronson commented 11 years ago

Looks great, thanks!