Skip to content

iefserge/templ.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Templ for vim

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 ALE and vim-go)

This plugin was originally forked from joerdav/templ.vim.

Install

To install with vim-plug, add to your .vimrc:

Plug 'iefserge/templ.vim'

Using Templ with ALE

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 = 1

Add 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 END

Optionally, replace FileType templ with FileType * to enable ALE keybindings in all files.

About

templ config for vim

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •