luaneovim

How to execute a Lua function after exiting insert mode in Neovim


Teach me please how to make Neovim execute a Lua function after exiting an insert mode.


Solution

  • Use an autocommand using the vim API:

    vim.api.nvim_create_autocmd("InsertLeave", {
      callback = function()
          print("Exited insert mode!");
      end
    });