I have the following Lua function:

local function submit_diff(diff_msg_file)
  vim.fn.termopen("arc diff HEAD^ -F " .. diff_msg_file, {
    on_exit = function(_, exit_code, _)
      if exit_code == 0 then

This does almost everything I want. It:

  1. Runs the command arc diff with the appropriate arguments
  2. I can delete the file speficied as an argument if the terminal command exits succesfully

The one problem is that no window is opened. The command being run is interactive, so I can't see what's going on since the buffer created by termopen doesn't seem to automatically create and attach to its own window.

Is there a way for me to either find the buffer created by termopen and then create a window to attach it to, or call termopen in such a way a window is created with the buffer attach, or should I be using something other than termopen?

  • In short, you can use the Neovim API nvim_buf_call to call termopen inside the callback (sure you need to load the buf you passing into nvim_buf_call into a window beforehand. (I was just solving a similar problem and got an answer.) Commented Feb 26, 2023 at 22:16

1 Answer 1


The solution for me here was to actually switch to just issuing a :term command. This meant I couldn't get a callback when the command finished, but I moved the cleanup work that I wanted to do into the actual term command itself. I made sure it was only run on success by using the && shell command.

local function submit_diff(diff_msg_file)
  vim.cmd("vsplit | term arc diff HEAD^ -F " .. diff_msg_file .. " && rm " .. diff_msg_file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.