How To Make A Hello World Neovim Plugin With Lua

June - 2021


NOTE: I don't think this is the best way to do this. It uses VimScript as well as Lua and seems to do a weird dance. Probably more strightforward to call lua directly

I'm looking to build a Neovim plugin with Lua. I couldn't find an article with a simple example. Digging through the docs I was able to put this one together. Setting up these files will provide a new command:


Running it will print Hello, Neovim! This is Lua! on the first line of the open document.

The Files

File: ~/.config/nvim/autoload/hello_neovim.vim

function hello_neovim#print_it() call setline(1, luaeval('require("hello_neovim").hello')) endfunction

File: ~/.config/nvim/lua/hello_neovim.lua

return Hello, Neovim! This is Lua!

File: ~/.config/nvim/plugin/hello_neovim.vim

if exists('g:hello_neovim_loaded') finish endif let g:hello_neovim_loaded = 1

command HelloNeovim :call hello_neovim#print_it()


The main tutorial that comes in the search results for making a neovim plugin with lua is this one. It's 153 lines of code, creates windows with borders, uses git calls, and doesn't show you how to actually install it. I wasn't able to follow it.

I think there's a way to isolate plugins during development, but I haven't figure that out yet.