This is a nvim plugin completely written from scratch
- How to write neovim plugins in Lua
- How to make UI for neovim plugins in Lua
- nanotee/nvim-lua-guide
- Neovim writing LUA plugins
- Getting started using Lua in Neovim
- From init.vim to init.lua
- Using LibUV in Neovim
- Writing NeoVim Plugins Part 1 / 3
- NeoVim Plugin 2 / 3 - Windows and Buffers!!!
When you want to do something and you can remember the command you can use:h nvim
. With that you will see a list of every function nvim has to over.
When you want you want to use those commands you have to prefix those with vim.api.
. Others can be accessed via vim.fn.
When you have variables defined in vimscript like let g:your_value = 42
, you can access this ariable with vim.g["value"]
. Remember when you make changes to a vimscript you have to source this file afterwards with :so %
A good starting point are the standard git files. Besides that we need at least two files lua/pluginname.lua
and plugin/pluginname.vim
. It all could be put in one file but it seems to better to split lua from vimscript.
In the plugin/pluginname.vim
following elements making sense:
This is the first line and prevents that the plugin is loaded twice.
if exists('g:loaded_pluginname') | finish | endif
After that we manage the user coptions.
let s:save_cpo = &cpo " save user option
set cpo&vim " reset them to defaults
Then we can give the command to run the plugin
command! Pluginname lua require'pluginname'.pluginname()
After the command has been run we can restore the coptions for the user.
let &cpo = s:save_cpo
unlet s:save_cpo
At last we set the plugin as loaded.
let g:loaded_pluginname = 1
Since plugins writen in lua we should communicate that.
if !has('nvim')
echohl Error
echom "Sorry this plugin only works with versions of neovim that support lua"
echohl clear
finish
endif