ntpeters / vim-better-whitespace

Better whitespace highlighting for Vim
The Unlicense
1.37k stars 82 forks source link

Sometimes you can't remove spaces when saving a file #147

Open onlycalm opened 3 years ago

onlycalm commented 3 years ago

Open file via VIM. Because neardtree can move the cursor to the window where the open file is located, the space cannot be deleted when saving the file. If you move the cursor to another window and then move back to the original window, the function will return to normal.

The configuration is as follows:

"autocmd StdinReadPre let s:std_in=1 "autocmd VimEnter NERDTree | if argc() > 0 || exists("s:std_in") | wincmd p | endif

let g:better_whitespace_enabled=1 let g:better_whitespace_ctermcolor='gray' let g:strip_whitespace_on_save=1 let g:strip_whitespace_confirm=0 let g:better_whitespace_operator='' let g:better_whitespace_blacklist=[] let g:current_line_whitespace_disabled_hard=0 let g:current_line_whitespace_disabled_soft=0

Cimbali commented 3 years ago

This works for me. Do you have by any chances let g:strip_only_modified_lines = 1 ?

I’m replicating this behaviour by

  1. opening a new window
  2. doing wincmd p

So for example: vim --cmd 'au VimEnter * | vert :new | wincmd p' some_file_here

What I’m seeing is that :w and :StripWhitespace work fine with your specified config. On the other hand :StripWhitespaceOnChangedLines does nothing (as no edits have been made yet).

onlycalm commented 3 years ago

Thank you for your reply. I've uploaded two GIF files, which can explain the problems I'm facing. Can you check them? 1 2

onlycalm commented 3 years ago

If I move the cursor to another window and then move it back, the :w instruction can remove the space.

onlycalm commented 3 years ago

If you need more information, please let me know. I'm afraid I didn't describe the problem clearly. Thanks

Cimbali commented 3 years ago

Hi @onlycalm, your screen captures seem to describe the problem well. I’m supposing some event gets missed or something but I didn’t have time to look into it yet (also I don’t have NERDTree installed)