vim-better-whitespace icon indicating copy to clipboard operation
vim-better-whitespace copied to clipboard

Sometimes you can't remove spaces when saving a file

Open onlycalm opened this issue 3 years ago • 5 comments

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

onlycalm avatar May 22 '21 14:05 onlycalm

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).

Cimbali avatar May 22 '21 17:05 Cimbali

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 avatar Jun 05 '21 14:06 onlycalm

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

onlycalm avatar Jun 05 '21 14:06 onlycalm

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

onlycalm avatar Jun 09 '21 12:06 onlycalm

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)

Cimbali avatar Jun 09 '21 14:06 Cimbali