3

I have multiple tab pages. Some tab pages only have open files, some only have :terminals open, and some have a mix of files and terminals.

At the end of the day, I want to quit Vim. Normally, I go through every tab page and close every window manually. But is there a better way? I tried :wqa, but that doesn't work because I have terminals running in some of my tab pages.

0

You can use :qa! to force vim to exit:

:qa[ll]!    Exit Vim.  Any changes to buffers are lost.
        Also see |:cquit|, it does the same but exits with a non-zero
        value.

As :qa! doesn't save buffer, you should use :wqa before that.

:qa! can be dangerous, a half-way stopped terminal might leave you garbage files.

You can also use ls R to list running terminal buffers and load them with :b bufnr.

Here is a command to list all running terminal buffers and modified readonly buffers in a new tab :

com ListUndead ListBuffers R =+
com -nargs=+ ListBuffers call s:list_buffers(<f-args>)

function s:list_buffers(...) abort

  let bufs = {}

  for flags in a:000
    let l = split( execute( printf('ls! %s', flags) ), "\n" )
    let l = map(l, { i,v -> matchstr(v, '\v^\s*\zs\d+') })
    for buf in l
      let bufs[ buf ] = buf
    endfor
  endfor

  let first = 1
  for buf in keys(bufs)
    if first
      exe 'tab sbuffer' buf
      let first = 0
    else
      exe 'sbuffer' buf
    endif
  endfor

endfunction
| improve this answer | |
0

If you don’t want to quit, but close all tabs, pick one and do :tabonly to keep it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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