Neovim Lua

Updated: 10 November 2024

~/.config/nvim/init.lua

-- Level 1 the function
function Foo() print 'bar' end
-- :lua Foo()

-- Level 2 user command using the function
vim.api.nvim_create_user_command('Foo', Foo, {})
-- :Foo

-- Level 3 function invoked by an event
vim.api.nvim_create_autocmd('TextYankPost', { callback = Foo })
-- try yanking some text

-- Level 4 map our function to a keyboard sequence
vim.keymap.set('n', 'xy', Foo)

Leave a comment