0

I'm opening a terminal buffer for my XML validation with the following command:

let term_buff_no = term_start(validate_cmd, {'term_rows': 10})

However, when running the same command again, a new terminal buffer is opened.

  1. How can i re-use the same buffer for displaying another round of results?
  2. When the job's exit status is OK, can i detect that and close the terminal buffer?
1
  • For (2), you could try the exit_cb and/or term_finish options. For (1) you would need to program something like "find the terminal in term_list() with the same command"
    – D. Ben Knoble
    Commented Jun 23, 2022 at 14:37

1 Answer 1

1

Re-using is quite easy - name your terminal buffer when starting it, but before you actually start it, check if a term buffer with such name already exists and delete it if yes. For example:

function s:RunCmdTerm(cmd, name)
  let cmd = a:cmd
  let name = a:name
  " close existing terminal buffer with the same name
  let ex_term_buf_no = bufnr(name)
  if ex_term_buf_no > -1
    execute 'bwipeout! ' . ex_term_buf_no
  endif
  " start the command itself
  let term_buf_no = term_start(cmd, {'term_name': name, 'term_rows': 10})
  " return to the editing buffer
  wincmd p
  return term_buf_no
endfunction

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.