VIM html autoindent not working
11,167
You have to add the following lines to your .vimrc
to make sure vim uses file-specific indentions:
filetype on
filetype plugin on
filetype indent on
This way it will indent html as html when the filetype is set to html
.
Author by
Tiddo
Updated on June 04, 2022Comments
-
Tiddo almost 2 years
I try to get autoindent to work in VIM with html files, but unfortunately it won't work. Autoindent works perfectly with other languages, but it just won't work with html. I've already tried setting the
filetype
tohtml
, as suggested in this question, but unfortunately it doesn't work either. Also, when I select everything and press = it doesn't indent as well, even though vim reportsXX lines indented
.My .vimrc file looks like this:
set autoindent set cindent set tabstop=4 set shiftwidth=2 set expandtab
Any suggestions?
-
darjab about 12 yearsYou can actually write that as "filetype plugin indent on", all in one line :)
-
BergmannF about 12 yearsNice to know - might artificially shorten my
.vimrc
:) -
valid over 10 yearsIf for some reason the above didn't work you may want to check if indentation instructions were loaded. In normal mode in
vi
type:scriptnames
to see scripts loaded. You should find oneindent.vim
which holds instructions on how to load further indentation instructions depending on the name of the file to load to a buffer and its filetype.