chrisbra/csv.vim

HiColumn is leaky

Closed this issue · 10 comments

HiColumn leaves trailing highlighting on other buffers.

Seems to be something to do with csv#HiCol in csv.vim/autoload/csv.vim.

Tested in a stripped down Vim configuration with only this plugin.

In another affected buffer, these don't clear the errant highlighting: :colo default, :2mat none. The only thing I can do is return to the buffer of the csv file and either :HiColumn! or :CSVInit, then return to the buffer of the other filetype.

what do you mean with leaky? I don't think the csv plugin uses highlight matches, but perhaps this is just hls highlighting that persists? Does :nohls fix it` Can you show a screen shot?

:nohls was such an obvious first thing to try I'd forgotten to mention that it also doesn't remove the leaked highlighting.

I ran again my stripped down vim configuration to grab some screen shots and noticed that the highlighting from :HiColumn even leaks into Netrw - image here.

hm, you seem to be changing the buffer in the window and the :HiColumn hightlighting isn't cleared then. Does :call clearmatches() does fix it?

Yes, I see that the leak is limited to the window that :HiColumn was called from.

In my workflows I often switch buffers within a window so now I've implemented in my vimrc:

inoremap <s-f7> :call clearmatches()<cr>
nnoremap <s-f7> :call clearmatches()<cr>
  • which allows me to clear the leaked highlighting from any other affected buffer.

that is actually puzzling, because :HiColumn highlighting should be removed, once you change editing another buffer in the current window:

csv.vim/autoload/csv.vim

Lines 230 to 257 in 15ff93e

fu! csv#DoAutoCommands() "{{{3
" Highlight column, on which the cursor is
if exists("g:csv_highlight_column") && g:csv_highlight_column =~? 'y'
exe "aug CSV_HI".bufnr('')
au!
exe "au CursorMoved <buffer=".bufnr('')."> HiColumn"
exe "au BufWinLeave <buffer=".bufnr('')."> sil! HiColumn!"
aug end
" Set highlighting for column, on which the cursor is currently
HiColumn
else
call csv#RemoveAutoHighlight()
endif
" undo autocommand:
let b:undo_ftplugin .= '| exe "sil! au! CSV_HI'.bufnr('').' CursorMoved <buffer> "'
let b:undo_ftplugin .= '| exe "sil! aug! CSV_HI'.bufnr('').'"'
let b:undo_ftplugin = 'exe "sil! HiColumn!" |' . b:undo_ftplugin
if has("gui_running") && !exists("#CSV_Menu#FileType")
augroup CSV_Menu
au!
au FileType * call csv#Menu(&ft=='csv')
au BufEnter <buffer> call csv#Menu(1) " enable
au BufLeave <buffer> call csv#Menu(0) " disable
au BufNewFile,BufNew * call csv#Menu(0)
augroup END
endif
endfu

So can you check when your csv buffer is loaded, that there exists a corresponding autocommand?

:au BufWinLeave

For me it certainly clears the highlighting when switching to another buffer.

Please provide a reproducible example how this happens? Also please specify what version you are using

I have made some changes in ba2c5ff please verify

In my $vimfiles/pack/packs-cp/opt/csv.vim,

$ git rev-parse --short HEAD
15ff93e

Just re-tested like this:

  1. I made a directory ~/.vimtest and from in there mkdir -p pack/packs-cp/opt into which I cloned csv.vim
  2. I created a vimrc.vim containing these statements:
set runtimepath=~/.vimtest,/usr/share/vim/vimfiles,/usr/share/vim/vim90,/usr/share/vim/vimfiles/after
source $VIMRUNTIME/defaults.vim
packadd csv.vim
  1. and I created test.csv containing these two lines:
header1,header2,header3
data1,data2,data3
  1. still in directory ~/.vimtest, vim -u ~/.vimtest/vimrc.vim test.csv
  2. in that testing version of Vim, I :HiColumn, which works, then e . to open Netrw showing the leaked highlighting.

- could there be something in $VIMRUNTIME/defaults.vim that conflicts with your plugin?

Well, can you please update to ba2c5ff and can you show the

:au BufWinLeave

when in a csv file?

Oh wait a second, you don't have a automatic highlighting setup? That might be the reason then.

Updated to 4fd8834, thanks.

:Bufferize au BufWinLeave gets me (relevant stuff):

--- Autocommands ---
...
CSV_HI2  BufWinLeave
    <buffer=2>
              sil! HiColumn!
              call csv#RemoveAutoHighlight()
              call csv#RemoveAutoHighlight()
...
CSV_HI2  BufWinLeave
    <buffer=2>
              call csv#RemoveAutoHighlight()

With your updated code I'm getting no more leaking of highlighting to other buffers, thanks.

A couple of points:

  • It'd be nice if when we return to the *.csv the column highlighting was still there.
  • Highlight column automatically (let g:csv_highlight_column = 'y')
    • I've not been using because, with my choice of colorscheme ,vim-colors-tomorrow, your column highlighting makes the cursor invisible. (This isn't an issue with jellybeans.vim colorscheme, which I prefer in nvim within my tmux.)
    • The column highlighting is lost when the buffer in the window has been changed.

you know, you can define your own highlighting.