r/neovim • • 1d ago

Need Help Looking for an HTML template plugin (simpler solution always welcome)

So I used NvChad for what seemed like forever.
But ever since version 0.12 I've been keeping things VERY minimal. I haven't done any web dev stuff in a long time, so I guess it would make sense that something like this would go unnoticed.

I'm not the biggest Lua fan...I mean I'd like to get better at it eventually, so for the time being I just sort of tolerate it and ever since the major update things have been kind of confusing.

But to get to the main point of this post; I was curious if there was some kind of plugin that could help me create an HTML template? It would be great if I didn't need another and there was a simpler solution that I'm not seeing.

Currently the plugins I'm using that I suspect would be related to the subject are:

mason, nvim-lspconfig, mason-lspconfig, and mason-tool-installer.

I'm also using the superhtml lsp, and while the popup works, apparently I guess it doesn't have any kind of "!DOCTYPE html" selection. I even tried the emmet-language server and that didn't work either.

I've never used it but, by any chance would blink.cmp solve this?

Any advice or feedback of course would be greatly appreciated. Many thanks in advance.

4 Upvotes

11 comments sorted by

7

u/trh-x 23h ago

You can use the built-in skeleton feature (:help skeleton) to use a template every time you open a new HTML file. Add the template somewhere, e.g. ~/.config/nvim/skeleton.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
</head>
<body>

</body>
</html>

Then add this to your init.lua:

vim.api.nvim_create_autocmd("BufNewFile", {
  pattern = "*.html",
  command = "0r ~/.config/nvim/skeleton.html | $d",
})

Now nvim foo.html or :edit foo.html will inject the template into the buffer for the new file.

2

u/thestoiccoder 13h ago

Thank you for this. While this solution does seem sort of clunky, it's good to know I can keep this in my back pocket just in case.

2

u/kilkil 18h ago

ooh didn't know this. TIL

2

u/Wonderful-Plastic316 lua 11h ago

I've been keeping things VERY minimal

mason, mason-lspconfig, mason-tool-installer

It's funny how "minimalism" is a personal thing. I wouldn't consider mason and co to be "minimal", but if it fits your needs :p

1

u/thestoiccoder 11h ago

Fair enough; but I decided to keep it as most people and tutorials have recommended leaving it installed as vim.pack is still very new. I find that if I discover that I'm not using something, I get rid of it as soon as I can without breaking anything else in relation to my limited understanding of Lua and vimscript.

2

u/MikeZ-FSU 6h ago

I usually just keep a template file in a directory and copy it to the new name. If it is something that I would tend to parameterize, I run it through one of the bazillion template engines, usually jinja, mustache, or gomplate with appropriate data definitions.

1

u/thestoiccoder 6h ago

I'm about ready to do something like that myself after the rabbit hole I've been going through.

"Should I go with blink.cmp or stick with nvim-cmp? And if I do, does that mean I also need luasnip and friendly snippets like did when I used kickstart?"

It's just getting too crazy for something essentially so simple...

2

u/MikeZ-FSU 6h ago

I keep a directory called "templates" that has script templates for various languages, markdown templates for various documentation things, etc. Since I live in the terminal it's a quick cp templates/whatever some/random/place/new-name.

When I was hand maintaining all my vim config (starting from vanilla vi on Irix in the 90s), completion was the biggest pain of all. A couple years ago, I realized I was spending way too much time tweaking configs, plugins, the whole thing. I tried several of the "nvim distros" and settled on LazyVim.

Since then, I occasionally swap a plugin in or out, but I never fool with completion other than to dial down how often it pops up. I'm not working on big code bases, so I don't need to pull names from a complicated tree, mostly just the files I'm working on.

1

u/thestoiccoder 5h ago

Thank you so much for confirming my hunches. I know exactly what you mean; I'm starting to go down a similar path.

I used to use NvChad, but later I eventually realized I just didn't use most things it offered, and besides I wanted to learn more about how Neovim and Lua worked behind the scenes so I could be more in control of the tools I use.

I mean, I love linux, keeping things simple, and having an efficient ecosystem to work in, but some times you just want something to work and get out of the way so you can get some real work done.

I believe I'm going to start doing this too.

1

u/Intrepid_Refuse_332 1d ago edited 1d ago

Install emmet language server from Mason then type `!` to get auto complete if you have it enabled already. Or manually trigger it with C-x C-o

Then check out the emmet cheat sheet.

1

u/thestoiccoder 1d ago

I tried that already and it didn't work. The only way the popup comes up is if I begin to type with '<'. Throughout all of the choices, starting an HTML template isn't there.