0

When I'm working with HTML in a PHP file and I press enter while in INSERT mode, my cursor goes to the start of the next line instead of going at the right positive therefore I have to press tab to position my cursor every time.

For example, I have the following in my index.php and my cursor is at the _ position:

<!DOCTYPE html>
<html>
    <head>_

If I press enter in INSERT mode, it becomes like this:

<!DOCTYPE html>
<html>
    <head>
_

Instead of this:

<!DOCTYPE html>
<html>
    <head>
        _

However, I do get the expected position when I modify a HTML file type.

Is there an option or plugin that change this behaviour?

  • Do you have :h 'autoindent' set in your config? And also maybe :h 'smartindent' and :h 'cindent'? – statox Jul 18 at 14:14
  • @statox No but autoindent is not doing what I want. It simply copies the indentation of the previous line. – Chin Leung Jul 18 at 14:17
  • I've also tried cindent and smartindent but they are both not working. – Chin Leung Jul 18 at 14:18
  • 1
    This answers to this SO question suggest three things: either you change the file type to set ft=phtml and hope it gets better, or you only do set ft=html and set ft=php depending on what kind of code you are editing in your php file, or you give this indent script a try. – statox Jul 18 at 14:22
  • 1
    If you want you can post the answer yourself, explaining why you think the plugin is a better option than the other ones. (And don't forget to self-accept your answer when you can :) ) – statox Jul 18 at 14:33
0

Using this plugin solved the issue for me:

Plug 'captbaritone/better-indent-support-for-php-with-html', { 'for': 'php' }

It is better than switching between php and html file type in my scenario because I have linters. So the html linter will throw me fake errors for my php code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.