1

I am new to vim and esp. in lua scripting. I want to create an autocmd such that all the jinja files will get yaml syntax highlighting.

local a = vim.api
a.nvim_create_autocmd( { "BufNewFile", "BufRead" }, {
pattern = { "*.j2" },
command = [[ lua(syntax = "html")]],
})

but this is not working. Could someone point the obvious.

DD.

romainl
  • 186,200
  • 21
  • 280
  • 313
DDStackoverflow
  • 505
  • 1
  • 11
  • 26

2 Answers2

0

I give you an Example on how i do Lua Syntaxhighlightning for my own *.luado files.
Before i have copied ( as super Q User: root.root ) /usr/share/nvim/runtime/syntax/lua.vim to /usr/share/nvim/runtime/syntax/luado.vim.
So i can change it independently from original lua.vim.
It is not necessary to change luado.vim for the Example below.

~/.config/nvim/lua/init.lua required by ~/.config/nvim/init.vim
( At First and off course before: syntax on )

--[[ Automatic Execution of Lua Oneliner if file extension *.luado
With Lua Syntaxhighlighting ]]
vim.api.nvim_create_autocmd({"BufEnter"},{
pattern = {"*.luado"},
command = "luado vim.api.nvim_command('setfiletype luado') load(line, 'koys_nvim_auto_luado')()"
})

Triggers at "BufEnter" and shows that "BufNewFile", "BufRead" not really needed.
( Every time before it is shown from Buffer ;-) )

Impression
Open a *.luado with Syntaxhighlight

Now lets change to next Buffer with :bn to test3.luado
Changed to next Buffer - Autocommand is executed the line

And back with :bp to test2.luado (Output of set)
:luado executing the line in test2.luado by autocommand
(test2.luado will be shown after ENTER/RETURN)

koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15
0

Using set instead of lua() seems to help

local a = vim.api
a.nvim_create_autocmd( { "BufNewFile", "BufRead" }, {
pattern = { "*.j2" },
command = [[ set syntax=html]],
})
mattrzr
  • 53
  • 1
  • 7