vim-indent-guides icon indicating copy to clipboard operation
vim-indent-guides copied to clipboard

Enabling per-buffer or per-filetype

Open kballenegger opened this issue 10 years ago • 11 comments
trafficstars

I'd like to have indent-guides only enabled for certain filetypes (those with significant whitespace). Right now, my configuration looks like this:

" indent-guide
let g:indent_guides_auto_colors = 0
hi clear IndentGuidesOdd
hi IndentGuidesEven ctermbg=235

autocmd FileType coffeescript :IndentGuidesEnable
autocmd FileType sass         :IndentGuidesEnable
autocmd FileType haml         :IndentGuidesEnable
autocmd FileType python       :IndentGuidesEnable

The problem is that indent-guides is enabled or disabled globally, and not per buffer, and refresh on buffer enter. Two potential solutions:

  1. Let indent-guide be enabled per-buffer, not globally. (This makes more sense to me anyway.) Then I can have the right autocmd set up for my use case.
  2. Let us specify a filetype inclusion whitelist, not an exclusion blacklist. I can't list every every file type I may ever want to edit with vim; but it's easy to list the ones I might want guides on.

kballenegger avatar Jan 29 '15 19:01 kballenegger

Is anybody interested in pointing me in the right direction for building this myself?

kballenegger avatar Mar 20 '15 21:03 kballenegger

Can't you use bufenter and bufleave instead of filetype

davidosomething avatar Mar 20 '15 21:03 davidosomething

It doesn't really make a difference. The IndentGuideEnable command is global, it enables it for all buffers.

kballenegger avatar Mar 20 '15 21:03 kballenegger

Is this issue dead? This is still very much a problem for me day-to-day :(.

kballenegger avatar Jun 29 '15 11:06 kballenegger

I think what @davidosomething mean is that you can setup BufEnter and BufLeave for your filetype that needs indent guide as a workaround. For example, if I want it ON only for Python:

augroup filetype_python
    autocmd!
    ...
    autocmd BufEnter * if &ft ==# 'python' | IndentGuidesEnable  | endif
    autocmd BufLeave * if &ft ==# 'python' | IndentGuidesDisable | endif
augroup END

So That the IndentGuide settings can be mostly confined to the active buffer's.

But I agree, this solution is cumbersome. And it looks weired when opening a buffer supposedly using IndentGuide and one not so side-by-side with split.

Is there any plan on making a alternative as @kballenegger suggested? It's a sensible request to me.

Ron89 avatar Apr 15 '16 09:04 Ron89

@Ron89 that looks similar to the indent_guides_exclude_filetypes option.

I don't mind the idea of the filetype whitelist behaviour that @kballenegger suggested, but I think it'd have to be a new option.

nathanaelkane avatar Apr 17 '16 11:04 nathanaelkane

g:indent_guides_exclude_filetypes works fine for my need. Sorry for not being able to spot it myself in the documentation.

Ron89 avatar Apr 17 '16 11:04 Ron89

Please re-open if indent_guides_exclude_filetypes isn't sufficient.

nathanaelkane avatar Dec 04 '16 21:12 nathanaelkane

Not sure how to re-open this, but I don't find indent_guides_exclude_filetypes to be sufficient. It's unreasonable to list every possible filetype in a blacklist when all you're looking is to enable it purely for a single filetype. That was mentioned in the original issue text as a suggestion:

Let us specify a filetype inclusion whitelist, not an exclusion blacklist. I can't list every every file type I may ever want to edit with vim; but it's easy to list the ones I might want guides on.

kballenegger avatar Mar 15 '17 23:03 kballenegger

Same here, i used BufEnter/BufLeave to toggle it, but when you have splits, going from one split to another disable it for the first split, would be better to enable it by filetype.

tshirtman avatar Sep 11 '17 11:09 tshirtman

A little bit old but I had similar needs as you @tshirtman / @kballenegger , i just pushed a PR who seems to satisfy my needs and think it should satisfy yours too.

Could you please confirm if it is the case ?

Regards,

rockandska avatar Dec 19 '18 21:12 rockandska