4

I can see that I've got a terminal buffer open by running :ls R which finds all buffers with a running terminal job, but I don't know how to capture just the buffer number.

The closest I can get is echo bufnr("cmd.exe") because the buffer name has the command the terminal is using. This isn't crossplatform though.

bufnr("R") doesn't seem to search the flags the same was :ls R does.

TankorSmash
  • 837
  • 1
  • 6
  • 14

1 Answers1

4
  1. By :h 'buftype'

    echo filter(map(getbufinfo(), 'v:val.bufnr'), 'getbufvar(v:val, "&buftype") is# "terminal"')
    
  2. By :h getwininfo()

     echo uniq(map(filter(getwininfo(), 'v:val.terminal'), 'v:val.bufnr'))
    
Matt
  • 20,685
  • 1
  • 11
  • 24