Skip to content

Confusing README regarding filetypes blacklisting #53

@tardypad

Description

@tardypad

The following part of the README is a bit confusing

*  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 BufWritePre * StripWhitespace`
        For exceptions of all see `g:better_whitespace_filetypes_blacklist`.

I wanted to have the plugin strips all whitespaces on save, except for markdown files
so I thought that adding both
autocmd BufWritePre * StripWhitespace
and
let g:better_whitespace_filetypes_blacklist=['markdown']
would do the trick

Unfortunately this better_whitespace_filetypes_blacklist variable is only affecting the highlighting.
It's only used in https://github.com/ntpeters/vim-better-whitespace/blob/master/plugin/better-whitespace.vim#L172-L174 after initialization

It's actually fine to have this variable only affects highlighting
I want the highlighting of whitespaces in markdown too, but I just don't want them to be removed on saving

I only think the documentation should be more clear there

I ended up adding the following in my vimrc

" Don't strip whitespaces for certain filetypes
" the plugin better_whitespace_filetypes_blacklist variable
" only affects the usage of the highlighting
fun! FiletypeFilteredStripWhitespace()
  if &ft =~ 'markdown'
    return
  endif
  StripWhitespace
endfun

" Strip all whitespaces on saving based on filetype
autocmd BufWritePre * call FiletypeFilteredStripWhitespace()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions