Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

How To Make A Hello World Neovim Plugin With Lua

### TL;DR

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:

Code

:HelloNeovim

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 = "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()

### Notes

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.