Run a Function Upon Exiting a Neovim Terminal

Viewed 239

By using the following code...

vim.fn.termopen("foo")

I can open a terminal with a certain command. What I want to do is run a Lua function from a plugin upon exiting the terminal.

Pseudo Code:

vim.fn.termopen("foo", run "lua require('my-plugin').someFunction()" upon exiting)

Is this possible?

1 Answers

After a bit of research, I found that there are two autocommands I can use that suit my needs

au TermClose * lua require('my-plugin').someFunction()

or

au TermLeave * lua require('my-plugin').someFunction()

The first one works better for me because I only want to run my function once the terminal is killed/closed. The second one is for if you want to run a function once the user switches from the terminal to something else.

Related