Scripting neovim config#

An excellent lua crash course for Neovim is TJ’s YouTube video “Everything You Need To Start Writing Lua”.

In Neovim, the lua scripting API consists of 3 layers

  1. The “Vim API”, inherited from Vim.

    These are accessed through vim.cmd and vim.fn respectively.

  1. The Nvim API written in C for use in remote plugins and GUIs.

    These are accessed through vim.api.

  1. The “Lua API” written in and specifically for Lua. These are any other functions accessible through vim.* not mentioned already. See lua-stdlib for more.

The lua-guide is worth reading through in its entirety and is pretty good.

Logging during plugin development#

Neovim has a built-in way to log thing which show up in :messages by default. We use nvim-lua/plenary.nvim to log things specific to something as follows

lua/vvn/log.lua#
return require("plenary.log").new({
  plugin = "vvn.precious",
  level = "info",
})

Then use it as follows

local log = require("vvn.log")
-- log.info("something")

The contents will show up in :messages as well as the log file vvn.precious.log in the log directory of stdpath, which is ~/.local/state/nvim/vvn.precious.log.

Tip

To see where stdpath is, run :=vim.fn.stdpath("log").