Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: explain how to integrate with vim #363

Closed
egtann opened this issue Dec 26, 2023 · 5 comments · Fixed by #769
Closed

docs: explain how to integrate with vim #363

egtann opened this issue Dec 26, 2023 · 5 comments · Fixed by #769
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed NeedsFix Needs implementing

Comments

@egtann
Copy link

egtann commented Dec 26, 2023

There's lots of docs for integrating with neovim here: https://templ.guide/commands-and-tools/ide-support/

It would be great to document how we can add "Format on Save" support to vim itself.

@a-h
Copy link
Owner

a-h commented Dec 26, 2023

I have no idea how to do this. It's probably a case of writing an autocmd to pipe through the templ fmt command instead of using the LSP API like Neovim can.

https://github.com/a-h/dotfiles/blob/33ea545ce1b0cca457c46b4689f745130eee5091/.config/nvim/lua/lsp.lua#L13-L14

I'd be happy to take a PR for the docs update if you find a way that works.

@iefserge
Copy link

iefserge commented Dec 28, 2023

This vimrc config worked for me:

set autoread
autocmd BufWritePost *.templ silent! execute "!PATH=\"$PATH:$(go env GOPATH)/bin\" templ fmt <afile> >/dev/null 2>&1" | redraw!
  • set autoread to automatically reload file on save
  • This sets PATH so doesn't require templ to be in PATH (only installed in go env bin)
  • Pipe stdout/stderr to /dev/null, to avoid screen blinking on save

@egtann
Copy link
Author

egtann commented Dec 29, 2023

This works great! Thank you!

@a-h
Copy link
Owner

a-h commented Dec 30, 2023

So, do we need another docs update to close this off, or are we happy we've got enough info now?

@egtann
Copy link
Author

egtann commented Dec 31, 2023

I think it’d be smart to include it in docs, since Vim is a widely used editor, and this is such an easy and dramatic way to improve the developer experience.

@joerdav joerdav changed the title Docs for how to integrate with vim docs: explain how to integrate with vim Jan 30, 2024
@joerdav joerdav added documentation Improvements or additions to documentation help wanted Extra attention is needed good first issue Good for newcomers NeedsFix Needs implementing labels Jan 30, 2024
@a-h a-h closed this as completed in #769 Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed NeedsFix Needs implementing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants