since we have the option to have a terminal inside a neovim buffer. I would very much like to have a way to "toggle" the buffer containing the terminal and have it appear in a fixed position like say the bottom of the screen.
I know that nerdtree does this for me, it toggles with a keybinding to always appear on my left side of the screen. what i wish for is the same with the terminal buffer in neovim. Is there anyone who knows of a plugin like this or how i would create one?
That's my solution to anyone who wanna hide/show a single neovim terminal window of any height.
The terminal will show at very bottom in insert mode. If you wanna change the split behaviour just edit botright new
to something else. :help opening-window
let g:term_buf = 0
let g:term_win = 0
function! Term_toggle(height)
if win_gotoid(g:term_win)
hide
else
botright new
exec "resize " . a:height
try
exec "buffer " . g:term_buf
catch
call termopen($SHELL, {"detach": 0})
let g:term_buf = bufnr("")
endtry
startinsert!
let g:term_win = win_getid()
endif
endfunction
nnoremap <M-t> :call Term_toggle(10)<cr>
tnoremap <M-t> <C-\><C-n>:call Term_toggle(10)<cr>
I might have a solution for you. The code below toggles a terminal on the far left with the f4-button:
let g:term_buf = 0
function! Term_toggle()
1wincmd w
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
topleft vnew
try
exec "buffer ".g:term_buf
catch
call termopen("bash", {"detach": 0})
let g:term_buf = bufnr("")
endtry
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With