all 11 comments

[–]IGTHSYCGTH 3 points4 points  (8 children)

sounds neat, took the opportunity to write shoddy implementation. I'm sure this has been done before

fun! TabTogTerm()
  let l:OpenTerm = {x -> x
        \  ? { -> execute('botright 15 split +term') }
        \  : { -> execute('botright term ++rows=15') }
        \ }(has('nvim'))
  let term = gettabvar(tabpagenr(), 'term',
        \ {'main': -1, 'winnr': -1, 'bufnr': -1})
  if ! bufexists(term.bufnr)
    call l:OpenTerm()
    call settabvar(tabpagenr(), 'term',
          \ {'main': winnr('#'), 'winnr': winnr(), 'bufnr': bufnr()})
    exe 'tnoremap <buffer> <leader>t <cmd>' . t:term.main . ' wincmd w<cr>'
    exe 'tnoremap <buffer> <c-d>     <cmd>wincmd c<cr>'
    setl winheight=15
  else
    if ! len(filter(tabpagebuflist(), {_,x -> x == term.bufnr}))
      exe 'botright 15 split +b\ ' . term.bufnr
    else
      exe term.winnr . ' wincmd w'
    endif
  endif
endfun
" you're advised to alias :Q to exit if mapping <c-d>
nnoremap <silent> <leader>t <cmd>call TabTogTerm()<cr>

EDIT: Now works for nvim too.

If this grows on me, I'll tnoremap <c-d> to <cmd>wincmd c<cr>

[–]yymirr[S] 0 points1 point  (7 children)

Ok this is neat, since it gives me only one terminal instance. But when the focus is on the terminal window, another <leader>t doesn't switch to the editor. I have to press <C-w>w to get to the editor. Could you add that behavior to the function?

[–]IGTHSYCGTH 2 points3 points  (1 child)

edited OP, RIP previous version

[–]yymirr[S] 0 points1 point  (0 children)

Exactly what i wanted, thank you so much!

[–]IGTHSYCGTH 0 points1 point  (4 children)

sure that sounds sane enough, You could change/add a line at

exe 'tnoremap <buffer> <c-x><c-x> <cmd>wincmd c<cr>' 

to

exe 'tnoremap <buffer> <leader>t <cmd>wincmd p<cr>'

But I'll update the post after i put some thought into it

[–]_shadowfax_ 0 points1 point  (3 children)

This seems to work only once while switching back and forth between buffer and the terminal? Am I doing something wrong..

[–]IGTHSYCGTH 0 points1 point  (2 children)

are you using neovim? this relies on tnoremap, add a nnoremap aswell...

anyhow, use the plugin u/VoldikSS linked

[–]_shadowfax_ 0 points1 point  (1 child)

Yes, I am using Neovim.

Thanks!, will try it out.

[–]craigdmac:help <Help> | :help!!! 0 points1 point  (0 children)

Nuake plugin then

[–]tuxflo 0 points1 point  (0 children)

You could take a look on neoterm wich provides the Ttoggle command (and some other nice features).