I don't like how vim-polyglot does indentation for my .html files. One apparent solution I found from researching online is to create ~/.vim/indent/html.vim and put the following line in it:
let b:did_indent = 1 This works! However, I'd much prefer it, if I could do without this one extra config file and just have this setting in my ~/.vim/vimrc with all the other settings. From reading vim-polyglot docs and looking at its source code, there is both
if exists("b:did_indent") "{{{ finish endif as well as:
if polyglot#init#is_disabled(expand('<sfile>:p'), 'html5', 'indent/html.vim') finish endif So I thought I could maybe simply set
let g:polyglot_disabled = ['html5'] to disable the plugin for .html files, as described on its GitHub repo website. But it seems to have no effect at all.
I'm new to Vim and vimscript and I'd appreciate any pointers. Either how to fix the vim-polyglot settings - or to move the did_indent workaround line into my vimrc.
To isolate the issue and to make it reproducible, I have completely deleted my ~/.vim folder and started fresh:
I have reduced my
~/.vim/vimrcto only the following 3 lines:set autoindent let g:polyglot_disabled = ['sensible'] packadd! vim-polyglotThe only other files in
~/.vimare in~/.vim/pack/plugins/opt/vim-polyglotfrom the most recent commit of its GitHub repo: https://github.com/sheerun/vim-polyglot/archive/bc8a81d3592dab86334f27d1d43c080ebf680d42.zip
Once I add an extra file ~/.vim/indent/html.vim with let b:did_indent = 1, the issue disappears.
Furthermore, I have verified that :set filetype? after opening the file indeed has output filetype=html, so the file is recognized as html. Also, I have compared the output from :scriptnames
- with
indent/html.vimhttps://pastebin.com/rfHMLuqL - compared to without
indent/html.vimhttps://pastebin.com/F49f7AMv
Here's a diff (with indent/html.vim on the left, without on the right):
48,51c48,57 < 48: ~/.vim/indent/html.vim < 49: ~/.vim/pack/plugins/opt/vim-polyglot/indent/html.vim < 50: /usr/share/vim/vim82/indent/html.vim < 51: /usr/share/vim/vim82/scripts.vim --- > 48: ~/.vim/pack/plugins/opt/vim-polyglot/indent/html.vim > 49: ~/.vim/pack/plugins/opt/vim-polyglot/indent/javascript.vim > 50: /usr/share/vim/vim82/indent/javascript.vim > 51: ~/.vim/pack/plugins/opt/vim-polyglot/after/indent/javascript.vim > 52: ~/.vim/pack/plugins/opt/vim-polyglot/after/indent/javascript-1.vim > 53: ~/.vim/pack/plugins/opt/vim-polyglot/after/indent/jsx.vim > 54: ~/.vim/pack/plugins/opt/vim-polyglot/after/indent/javascript-2.vim > 55: ~/.vim/pack/plugins/opt/vim-polyglot/indent/graphql.vim > 56: /usr/share/vim/vim82/indent/html.vim > 57: /usr/share/vim/vim82/scripts.vim But I don't see any relevant difference. Maybe someone else does.
The command :set cindent? smartindent? indentexpr? autoindent? currently says:
nocindent nosmartindent indentexpr=HtmlIndent() autoindent Putting let g:polyglot_disabled = ['sensible', 'html5'] which is supposed to disable vim-polyglot for .html, doesn't change anything (or overwrites HtmlIndent with the same name):
nocindent nosmartindent indentexpr=HtmlIndent() autoindent However, with putting the extra ~/.vim/indent/html.vim, I get:
nocindent nosmartindent indentexpr= autoindent My vim version is updated, most recent one for current Debian LTS release 11 (bullseye). The 3 topmost lines of output from :version are:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 01 2021 01:51:08) Included patches: 1-2434 Extra patches: 8.2.3402, 8.2.3403, 8.2.3409, 8.2.3428
~/.vimdir is a bit extreme, you can usevim --cleanorvim -N -u NONEinstead. Just a side note.