Vim config for editing templ files in vim.
This plugin integrates with ALE and vim-go to support Templ LSP and auto-formatter.
Features:
- Syntax highlighting
- Indentation that matches Go indent rules
- Support commenting with tcomment_vim
- Go to definition from Go files to Templ files (requires
ALEandvim-go)
This plugin was originally forked from joerdav/templ.vim.
To install with vim-plug, add to your .vimrc:
Plug 'iefserge/templ.vim'This plugin integrates with ALE and vim-go to support Templ LSP and auto-formatter.
Enable templ linter (or add this to your existing linters):
let g:ale_linters = {
\ 'templ': ['templ'],
\}To enable format on save, enable templfmt fixer and ale_fix_on_save flag:
let g:ale_fixers = {'templ': ['templfmt']}
let g:ale_fix_on_save = 1Add ALE keybindings and override "Go to Definition" for Go files:
augroup ale_keybindings
autocmd!
autocmd FileType templ nmap <buffer> gd :ALEGoToDefinition<CR>
autocmd FileType templ nmap <buffer> gr :ALEFindReferences<CR>
autocmd FileType templ nmap <buffer> gi :ALEGoToImplementation<CR>
autocmd FileType templ nmap <buffer> gt :ALEGoToTypeDefinition<CR>
autocmd FileType templ nmap <buffer> K :ALEHover<CR>
autocmd FileType templ nmap <buffer> <leader>rn :ALERename<CR>
autocmd FileType templ nmap <buffer> <leader>ca :ALECodeAction<CR>
autocmd FileType templ nmap <buffer> [d :ALEPrevious<CR>
autocmd FileType templ nmap <buffer> ]d :ALENext<CR>
autocmd FileType templ nmap <buffer> <leader>f :ALEFix<CR>
" Go override (go -> templ)
autocmd FileType go nmap <buffer> gd :call TemplGoToDefinition()<CR>
augroup ENDOptionally, replace FileType templ with FileType * to enable ALE keybindings in all files.