SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function! TerminalTab()
  2.     " find evey terminal buffer
  3.     let b = filter(range(1, bufnr('$')),
  4.                 'getbufvar(v:val, "&buftype", "ERROR") == "terminal"')
  5.     " if no terminal buffers are available
  6.     if len(b) == 0
  7.         tabnew
  8.         terminal
  9.     else
  10.         " we only care for the first terminal buffer
  11.         let b = b[0]
  12.         let bb = win_findbuf(b)
  13.         " if there is no window in any tab that contains a terminal
  14.         if len(bb) == 0
  15.             tabnew
  16.             buffer b
  17.         else
  18.             " again we only care for the first match
  19.             let bb = win_id2tabwin(bb[0])
  20.             exe 'tabnext'.bb[0]
  21.             exe bb[1].'wincmd w'
  22.         endif
  23.     endif
  24.     " we open a terminal to do something
  25.     startinsert
  26. endfunc
  27. nmap <silent> <leader>s :call TerminalTab()<cr>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top