Back to Blog
2025-06-05Abyan Dimas

Building Your First Neovim Plugin with Lua

Lua Code

You love LazyVim. Now you want to create your own tools. Neovim's switch from VimScript to Lua triggered a renaissance in the ecosystem.

Project Structure

A Neovim plugin is just a folder.

my-plugin/
├── lua/
│   └── my-plugin/
│       └── init.lua
└── plugin/
    └── my-plugin.lua

The Logic (lua/my-plugin/init.lua)

local M = {}

M.setup = function(opts)
    print("My Plugin Setup Called!")
end

M.hello = function()
    print("Hello from Neovim!")
    vim.notify("This is a notification", vim.log.levels.INFO)
end

return M

The Command (plugin/my-plugin.lua)

Expose your Lua function as a Vim command.

vim.api.nvim_create_user_command('HelloPlugin', function()
    require('my-plugin').hello()
end, {})

Loading It

Use lazy.nvim to load your local plugin:

{
  dir = "~/projects/my-plugin",
  config = function()
    require("my-plugin").setup()
  end
}

Restart Neovim and run :HelloPlugin. You are now a plugin author!

Share this article

Read Next