Create A Local Neovim Lua Plugin
Introduction
I'm starting to experiment more with Neovim plugins. Most of the directions/tutorials I found about how to set one up locally confuse me. This is what I came up with after a bunch of searching and trial and error. It uses the lazy
1 plugin manager for installation.
The Steps
-
Create the directory structure for a
new_plugin.nvim
plugin inside the a~/workshop
directory:mkdir -p ~/workshop/new_plugin.nvim/lua/new_plugin
-
Create a
.lua
file at:~/workshop/new_plugin.nvim/lua/new_plugin/init.lua With the contents:
local M = {} vim.keymap.set("n", "<Leader>8", function() M.do_something() end) end print("Doing Something") end return M
-
Find the
require('lazy').setup({})
section inside~/.config/nvim/init.lua and addrequire('lazy').setup({ -- all the stuff })
And add put this
dir
statement inside it like this:require('lazy').setup({ { dir = "~/workshop/new_plugin.nvim" }, -- all the other stuff })
-
Somewhere after the
require('lazy').setup({})
stuff add this line in the~/config.nvim/init.lua file(NOTE: This is only necessary if you need to do specific setup stuff. The example shows setting a hotkey, but that can be done (and I like it better) in a keymapping file)
require('new_plugin').setup()
This particular example prints Doing Something when you hit the leader
key followed by 8
. Nothing spectacular there. Just a simple function to show the plugin is working.
References
This is the page where things finally clicked. It's got some extra cruft but it's what got me started.