Fork me on GitHub
#vim
<
2022-02-15
>
Chase16:02:26

General vim question for you folks cuz I wasn't able to get help on the neovim and coc gitters: I've been doing a lot of html and I have autocomplete working fine but the behavior I want is like in VSC where when you have `<div>|</div>` and hit enter it autoindents the cursor and pushes the closing tag to it's own line like so:

<div>
  |
</div>
Right now I just get:
<div>
|</div>
which is no huge deal obviously but I would love to streamline that and not have to manually format it correctly because my autoformatter doesn't give me the desired behavior after the fact either.

skynet16:02:36

really not sure, mine does the same. this plugin makes it so that you press > in that situation and it lays things out like you want <https://github.com/alvan/vim-closetag> but idk how you would get the same effect with enter

Zoltan Kalmar16:02:28

what does :verbose set indentexpr? say?

Chase17:02:56

` indentexpr=HtmlIndent() Last set from /usr/local/share/nvim/runtime/indent/html.vim line 36 `

Chase17:02:42

indent works when I go from say <body>| and hit enter. It just doesn't work when the cursor is in between opening and closing tags

Zoltan Kalmar17:02:15

I have the same indentexpr and it works as expected. However, I’m on the OSX stock vim not on neovim

Chase17:02:53

Oh yeah? dang. I want that. lol

Chase17:02:20

what kind of lsp and/or html plugins do you use?

Zoltan Kalmar17:02:42

I use CoC and I don’t have any html plugin

Chase17:02:53

Hmmm. Do you use coc-html and/or coc-html? Sorry for pestering, just trying to track this behavior down.

Zoltan Kalmar17:02:54

and if I disable CoC, vim produces the same wrong indent as you have

Zoltan Kalmar17:02:54

here is the list of loaded vim scripts:

1: /usr/share/vim/vimrc
  2: ~/.vim/vimrc
  3: /usr/share/vim/vim82/defaults.vim
  4: /usr/share/vim/vim82/filetype.vim
  5: /usr/share/vim/vim82/ftplugin.vim
  6: /usr/share/vim/vim82/indent.vim
  7: /usr/share/vim/vim82/syntax/syntax.vim
  8: /usr/share/vim/vim82/syntax/synload.vim
  9: /usr/share/vim/vim82/syntax/syncolor.vim
 10: /usr/share/vim/vim82/autoload/netrw_gitignore.vim
 11: ~/.vim/pack/coc/opt/coc.nvim/plugin/coc.vim
 12: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc/rpc.vim
 13: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc/util.vim
 14: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc/client.vim
 15: ~/.vim/coc.vim
 16: /usr/share/vim/vim82/autoload/dist/ft.vim
 17: /usr/share/vim/vim82/ftplugin/xhtml.vim
 18: /usr/share/vim/vim82/ftplugin/xml.vim
 19: /usr/share/vim/vim82/ftplugin/html.vim
 20: /usr/share/vim/vim82/autoload/htmlcomplete.vim
 21: /usr/share/vim/vim82/indent/xhtml.vim
 22: /usr/share/vim/vim82/indent/html.vim
 23: /usr/share/vim/vim82/indent/javascript.vim
 24: /usr/share/vim/vim82/syntax/xhtml.vim
 25: /usr/share/vim/vim82/syntax/html.vim
 26: /usr/share/vim/vim82/syntax/javascript.vim
 27: /usr/share/vim/vim82/syntax/vb.vim
 28: /usr/share/vim/vim82/syntax/css.vim
 29: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc/api.vim
 30: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc.vim
 31: /private/var/folders/b5/y3y754c96g5bbqj4mdn15dnr0000gp/T/vBDjv1V/coc.nvim-25774/coc-25774.vim
 32: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc/cursor.vim
 33: ~/.vim/pack/coc/opt/coc.nvim/autoload/coc/float.vim

Chase17:02:53

I seem to have those same things but I imagine that is for the vim installed on my system, not neovim. I suspect that is where the different behavior is coming from. vim vs neovim but no clue how to clarify that

Zoltan Kalmar17:02:09

I can test it for you but my neovim is broken. brew cannot compile it for a while. let me try to fix that first

Chase17:02:05

Oh, you already spent too much time on me. Haha. I appreciate it but don't bother yourself

Zoltan Kalmar17:02:16

ok, so I fixed my neovim and installed CoC using packer

use {'neoclide/coc.nvim', branch = 'release'}
and HTML indent works for me in neovim too

Chase18:02:52

That did it!

Chase18:02:55

Thank you so much

Chase18:02:00

I thought I basically copied the example coc config too but it was years ago, not sure why I didn't have those two lines in there. I have everything before and after of course. haha

Chase18:02:18

Actually that example config seems much bigger, I assume it's been added to over the years. Anyways, thanks so much. Huge quality of life improvement while doing html