Create A Hello World Neovim Plugin In Lua

June - 2021

This is a basic setup for creating a Neovim plugin in Lua. After adding the files and restarting Neovim, you can run :HelloWorld which will print "Hello, Lua Plugin" on the command line. h

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

if exists('g:loaded_hello_world') | finish | endif

let s:save_cpo = &cpo
set cpo&vim

command! HelloWorld lua require'hello_world'.hello_world()

let &cpo = s:save_cpo
unlet s:save_cpo

let g:loaded_hello_world = 1

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

local function hello_world()
    print("Hello, Lua Plugin")

return {
    hello_world = hello_world