2

I can't get autoindentation to work for me in Vim. Anytime I press return, my cursor always goes to the first column on the next line and I have to manually indent the correct amount of space before typing. Is there any way to fix this? None of the existing answers I found SO have helped. I'm editing a Laravel view file called login.blade.php.

Here is the contents of my .vimrc:

syntax on
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
set cindent
colorscheme itg_flat

ADDITIONAL INFO

It appears this is only an issue in .blade.php files. I think the problem is that it's a .php file but contains HTML code. So the HTML code is not being intended properly since the files extensions is php. If I write HTML code in a .html file, it works correctly.

flyingL123
  • 7,686
  • 11
  • 66
  • 135

1 Answers1

1

I'm probably a little late to help the author of this question but for anyone else who is struggling with this issue I was able to fix it by changing the filetype and syntax of the blade.php files to html. Autoindentation then worked as expected.

You can do this by adding a couple of lines in your vimrc as follows:

autocmd BufNewFile,BufRead *.blade.php set syntax=html
autocmd BufNewFile,BufRead *.blade.php set filetype=html
  • Vim's own filetype plugin for PHP turns off `autoindent`, `cindent` and `smartindent`. Thankfully, Vim provide's a standard way to override settings set by filetype plugins, either before or after the plugins are loaded. Consult `:help ftplugin-overrule` for a better way to re-enable `autoindent` for PHP files. – dekarpaulvictor Jan 17 '22 at 09:00