Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #100

Merged
merged 22 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a6c1f89
Allow per-buffer toggling to override global
Cimbali Jan 16, 2019
cc64b53
Respect global choice in current detection
Cimbali Jan 16, 2019
6153f49
Refactor for readability/maintanability
Cimbali Jan 17, 2019
869c71a
Update docs to mirror refactor, fix #91 collisions
Cimbali Jan 17, 2019
fd3be02
Fix #92: Correctly re-init on colorscheme change
Cimbali Jan 17, 2019
98b7902
Add mechanism for confirming whitespace stripping
Cimbali Jan 18, 2019
ccf921c
Add option to only strip whitespace on modified lines
Cimbali Jan 18, 2019
46d89a6
Add option to disable stripping-on-save on large files
Cimbali Jan 18, 2019
08df151
Adjust documentations
Cimbali Jan 20, 2019
3f3ecda
Check if file exists instead of file name non-emtpy
Cimbali Jan 23, 2019
ddb78c2
Fix typo in doc/better-whitespace.txt
ntpeters Jan 24, 2019
91cc75c
Fix whitespace search to also match current line
ntpeters Jan 24, 2019
4270857
Correct missing sentence in doc
Cimbali Jan 24, 2019
d004257
Clarify ShouldStripWhitespace role, call diff less
Cimbali Jan 24, 2019
a552fbd
Fix incorrect diff for last line of file
Cimbali Jan 24, 2019
6e407aa
Make max lines more explicit and default to 1000
Cimbali Jan 24, 2019
bff74c8
Make a command to manually strip lines on changed lines
Cimbali Jan 24, 2019
1f27b9d
Remove unused bangs from commands
Cimbali Jan 25, 2019
aa5b80e
Show errors to user, except E486: Pattern not found
Cimbali Jan 25, 2019
8ffbfc4
Add error for &noro, respect range for changed lines
Cimbali Jan 25, 2019
7691a8c
Add a deprecation warning about in the doc
Cimbali Jan 25, 2019
1e09e6d
Add error number so people can look the error up
Cimbali Jan 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 74 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,21 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
:ToggleWhitespace
```

* To disable highlighting for the current line in normal mode call:
```vim
: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
* The highlighting for the current line in normal mode can be disabled in two ways:
* ```vim
let g:current_line_whitespace_disabled_hard=1
```
This 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:
```vim
:CurrentLineWhitespaceOn
```
* ```vim
let g:current_line_whitespace_disabled_soft=1
```
This 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 clean extra whitespace, call:
```vim
Expand Down Expand Up @@ -128,6 +124,30 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
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` )

* If you want to disable automatically stripping whitespace for large files, you can specify
a maximum number of lines (e.g. 1000) by adding the following to your `~/.vimrc`:

```vim
let g:strip_max_file_size = 1000
```

This overrides `let g:strip_whitespace_on_save` but not `:EnableStripWhitespaceOnSave`.
Set to `0` to deactivate.

* By default, you will be asked for confirmation before whitespace is
stripped when you save the file. This can be disabled by adding the
following to your `~/.vimrc`:
```
let g:strip_whitespace_confirm=0
```

* By default, all the lines in the file will have their trailing whitespace stripped
when you save the file. This can be changed to only the modified lines, by adding
the following to your `~/.vimrc`:
```
let g:strip_only_modified_lines=0
```

* To disable this plugin for specific file types, add the following to your `~/.vimrc`:
```vim
let g:better_whitespace_filetypes_blacklist=['<filetype1>', '<filetype2>', '<etc>']
Expand Down Expand Up @@ -300,6 +320,43 @@ A: If you know of a better way to do something I am attempting in this plugin,
me or make the changes yourself and open a pull request. If I am doing something that is bad
or can be improved, I am more than willing to hear about it!

## Deprecated commands
Cimbali marked this conversation as resolved.
Show resolved Hide resolved
Toggling the current line whitespace mode is now a plugin configuration,
and can not be done dynamically anymore. Thus the folowing commands are now deprecated:

```vim
:CurrentLineWhitespaceOff <level>
```
where `<level>` is either `hard` or `soft`, and:

```vim
:CurrentLineWhitespaceOn
```

If you really miss this feature, its withdrawal can easily be overriden
by adding the following to the vimrc (after loading the plugin initially):

```vim
fun! BetterWhitespaceCurrentLineMode(type)
" set setting to whatever was passed
let g:current_line_whitespace_disabled_soft=a:type == 'soft'
let g:current_line_whitespace_disabled_hard=a:type == 'hard'
" reload plugin
unlet! g:loaded_better_whitespace_plugin
runtime plugin/better-whitespace.vim
" Re-override the deprecated commands
command! -nargs=1 CurrentLineWhitespaceOff call BetterWhitespaceCurrentLineMode(<f-args>)
command! CurrentLineWhitespaceOn call BetterWhitespaceCurrentLineMode('off')
" Manually trigger change for current buffer.
" BufWinEnter will take care of the rest.
filetype detect
endfun

" Override deprecated commands, after (!) loading plugin
command! -nargs=1 CurrentLineWhitespaceOff call BetterWhitespaceCurrentLineMode(<f-args>)
command! CurrentLineWhitespaceOn call BetterWhitespaceCurrentLineMode('off')
```

## Promotion
If you like this plugin, please star it on Github and vote it up at Vim.org!

Expand Down
123 changes: 91 additions & 32 deletions doc/better-whitespace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,120 @@ modes as well (see options below).
To blacklist certain filetypes, set 'g:better_whitespace_filetypes_blacklist'
to a list of the desired filetypes.

COMMANDS *better-whitespace-commands*

*ToggleWhitespace*
:ToggleWhitespace *better-whitespace-:ToggleWhitespace*
:EnableWhitespace *better-whitespace-:EnableWhitespace*
:DisableWhitespace *better-whitespace-:DisableWhitespace*

Call :ToggleWhitespace to toggle whitespace highlighting on/off.
Call these functions to toggle whitespace highlighting on/off.
This will set the highlighting of extraneous whitespace for the entire file.

*EnableWhitespace*

To enable whitespace highlighting, call :EnableWhitespace. This will enable
To disable whitespace highlighting, call :DisableWhitespace. This will disable
highlighting of extraneous whitespace for the entire file.

*DisableWhitespace*
:[range]NextTrailingWhitespace *better-whitespace-:NextTrailingWhitespace*
:[range]PrevTrailingWhitespace *better-whitespace-:PrevTrailingWhitespace*

To disable whitespace highlighting, call :DisableWhitespace. This will disable
highlighting of extraneous whitespace for the entire file.
These functions will respectively take you to the next and previous trailing whitespace
in the ranged that they are passed (by default the whole file).

:[range]StripWhitespace[!] *better-whitespace-:StripWhitespace*

Removes extra whitespace, by default 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. With the !, ignores &readonly.

*StripWhitespace*
:[range]StripWhitespaceOnChangedLines[!] *better-whitespace-:StripWhitespaceOnChangedLines*

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.
Like :StripWhitespace, but only on the lines that are modified.

*ToggleStripWhitespaceOnSave*
:ToggleStripWhitespaceOnSave *better-whitespace-:ToggleStripWhitespaceOnSave*
:EnableStripWhitespaceOnSave *better-whitespace-:EnableStripWhitespaceOnSave*
:DisableStripWhitespaceOnSave *better-whitespace-:DisableStripWhitespaceOnSave*

This enables/disables stripping of extra whitespace on file save.
If `g:strip_only_modified_lines` is set to 1, only modified lines will be stripped.

*CurrentLineWhitespaceOff*

Calling :CurrentLineWhitespaceOff with the option either 'hard' or 'soft' will
disable whitespace highlighting for the current line.
DEPRECATED: :CurrentLineWhitespaceOn and :CurrentLineWhitespaceOff with the
option either 'hard' or 'soft' are now deprecated and replaced by the
following preferences:
`g:current_line_whitespace_disabled_hard`
`g:current_line_whitespace_disabled_soft`

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
PREFERENCES *better-whitespace-preferences*

Call :CurrentLineWhitespaceOn to enable whitespace highlighting for the current
line. Highlighting is still disabled for the current line while in insert mode.
`g:better_whitespace_enabled` (defaults to 1)
Set this to enable whitespace highlighting by default, set to 0 to disable it.

`g:better_whitespace_filetypes_blacklist` (defaults to ['diff', 'gitcommit',
'unite', 'qf', 'help', 'markdown'])
Disables better-whitespace by default on these file types.
Overrides `g:better_whitespace_enabled`, and can be manually overriden with
|better-whitespace-:EnableWhitespace| and related commands.

`g:strip_only_modified_lines` (defaults to 0)
When stripping whitespace on save, only perform the stripping on the lines
that have been modified.
Uses `diff`, which should be available on all platforms (see |E810|).

`g:strip_max_file_size` (defaults to 1000)
Skip stripping whitespace on files that have more lines than the value in this
variable. 0 means disabled, thus strip for any file size. This can be manually
overriden with |better-whitespace-:EnableStripWhitespaceOnSave| and related commands.

`g:better_whitespace_operator` *better-whitespace-operator*

*operator*
By default, an operator is provided mapped to: <leader>s.
To modify the key mapping for this operator, set g:better_whitespace_operator.
To modify the key mapping for this operator, set `g:better_whitespace_operator`.
This operator will strip whitespace over the currently selected region in visual
mode, or for the following motion in normal mode.
mode, or for the following motion in normal mode. Set an empty value to disable.

Note: This operator will not be mapped if an existing, user-defined mapping is
detected for the provided operator value.

*better-whitespace-colors*
Set the highlight color for trailing whitespaces:
`g:better_whitespace_ctermcolor` (defaults to 'red')
`g:better_whitespace_guicolor` (defaults to '#FF0000')

*better-whitespace-current_line*
`g:current_line_whitespace_disabled_hard` (defaults to 0)
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)
WARNING: Ignored if g:current_line_whitespace_disabled_soft is set.

`g:current_line_whitespace_disabled_soft` (defaults to 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.


`g:strip_whitespace_confirm` (defaults to 1)
Set to 0 to deactivate asking for confirmation before whitespace is
stripped when you save the file.

`g:show_spaces_that_precede_tabs` (defaults to 0)
Set this to match space characters that appear before or in-between tabs

`g:strip_whitespace_on_save` (defaults to 0)
Set this to enable stripping whitespace on file save for files where
Cimbali marked this conversation as resolved.
Show resolved Hide resolved
better-whitespace is enabled.

`g:strip_whitelines_at_eof` (defaults to 0)
Set this to enable stripping white lines at the end of the file when we
strip whitespace from the end of lines.

`g:better_whitespace_skip_empty_lines` (defaults to 0)
Skips empty (whitespace-only) lines for highlighting.



Repository exists at: http://github.com/ntpeters/vim-better-whitespace

Originally inspired by: https://github.com/bronson/vim-trailing-whitespace
Expand Down
Loading