vim-indent-guides
vim-indent-guides copied to clipboard
Enabling per-buffer or per-filetype
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:
- Let indent-guide be enabled per-buffer, not globally. (This makes more sense to me anyway.) Then I can have the right
autocmdset up for my use case. - 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.
Is anybody interested in pointing me in the right direction for building this myself?
Can't you use bufenter and bufleave instead of filetype
It doesn't really make a difference. The IndentGuideEnable command is global, it enables it for all buffers.
Is this issue dead? This is still very much a problem for me day-to-day :(.
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 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.
g:indent_guides_exclude_filetypes works fine for my need. Sorry for not being able to spot it myself in the documentation.
Please re-open if indent_guides_exclude_filetypes isn't sufficient.
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.
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.
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,