toggle neovim terminal buffer like nerdtree plugin [closed]
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?
vim-plugin nerdtree neovim
closed as off-topic by Paul Roub, Samuel Liew♦ Nov 14 '18 at 1:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Paul Roub, Samuel Liew
add a comment |
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?
vim-plugin nerdtree neovim
closed as off-topic by Paul Roub, Samuel Liew♦ Nov 14 '18 at 1:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Paul Roub, Samuel Liew
add a comment |
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?
vim-plugin nerdtree neovim
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?
vim-plugin nerdtree neovim
vim-plugin nerdtree neovim
asked May 14 '16 at 22:10
KristofferKristoffer
10910
10910
closed as off-topic by Paul Roub, Samuel Liew♦ Nov 14 '18 at 1:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Paul Roub, Samuel Liew
closed as off-topic by Paul Roub, Samuel Liew♦ Nov 14 '18 at 1:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Paul Roub, Samuel Liew
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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>
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
I am not very familiar with remote windows, but I would think that you could usewindohere. Send a command to all windows, and savewinnr()for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.
– jonathf
May 19 '16 at 7:07
As for the[no name], I'm not sure what is going on. If theexecterm fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?
– jonathf
May 19 '16 at 7:13
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
|
show 1 more comment
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>
add a comment |
I Think this must be a little better more IDE Like,
let g:term_buf = 0
function! Term_toggle()
1wincmd w
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
rightbelow new
12winc -
try
exec "buffer ".g:term_buf
catch
call termopen("bash", "detach": 0)
let g:term_buf = bufnr("")
endtry
set laststatus=0
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
" Terminal go back to normal mode
tnoremap <Esc> <C-><C-n>
" When switching to terminal windows it goes into insert mode automatically
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
add a comment |
An simple solution, but it deletes the buffer:
nnoremap <silent> <F3> :split term://zsh <CR>
tnoreamp <silent> <F3> <C-><C-n> :bd! <CR>
autocmd TermOpen * startinsert
the terminal buffer needs to be selected to be closed!
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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>
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
I am not very familiar with remote windows, but I would think that you could usewindohere. Send a command to all windows, and savewinnr()for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.
– jonathf
May 19 '16 at 7:07
As for the[no name], I'm not sure what is going on. If theexecterm fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?
– jonathf
May 19 '16 at 7:13
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
|
show 1 more comment
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>
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
I am not very familiar with remote windows, but I would think that you could usewindohere. Send a command to all windows, and savewinnr()for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.
– jonathf
May 19 '16 at 7:07
As for the[no name], I'm not sure what is going on. If theexecterm fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?
– jonathf
May 19 '16 at 7:13
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
|
show 1 more comment
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>
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>
answered May 15 '16 at 13:11
jonathfjonathf
31625
31625
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
I am not very familiar with remote windows, but I would think that you could usewindohere. Send a command to all windows, and savewinnr()for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.
– jonathf
May 19 '16 at 7:07
As for the[no name], I'm not sure what is going on. If theexecterm fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?
– jonathf
May 19 '16 at 7:13
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
|
show 1 more comment
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
I am not very familiar with remote windows, but I would think that you could usewindohere. Send a command to all windows, and savewinnr()for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.
– jonathf
May 19 '16 at 7:07
As for the[no name], I'm not sure what is going on. If theexecterm fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?
– jonathf
May 19 '16 at 7:13
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
Thanks! That actually works somewhat! i am trying to get it to start work for the bottom, but it refuses to toggle, it jus opens a new buffer window instead. i changed the line: 'topleft vnew' to 'botright new' any ideas?
– Kristoffer
May 16 '16 at 11:22
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
The command also adds a lot of [No name] buffers
– Kristoffer
May 16 '16 at 11:30
I am not very familiar with remote windows, but I would think that you could use
windo here. Send a command to all windows, and save winnr() for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.– jonathf
May 19 '16 at 7:07
I am not very familiar with remote windows, but I would think that you could use
windo here. Send a command to all windows, and save winnr() for the window that are terminal buffers to a global variable. Then switch to that window and do the stuff from my function.– jonathf
May 19 '16 at 7:07
As for the
[no name], I'm not sure what is going on. If the exec term fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?– jonathf
May 19 '16 at 7:13
As for the
[no name], I'm not sure what is going on. If the exec term fails every time it is run, then obviously it will respawn and hide a lot of buffers, but I thought the code dealt with that. Is your terminal the same one on each toggle, or do you get a new spawn?– jonathf
May 19 '16 at 7:13
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
No i checked that, the exec succeds everytime. Also i changed the 'call termopen...' to 'terminal' gives the same results. The terminal is the same even thought it creates a lot of [no name]-buffers. I tried to modify it so instead of 1wincmd i would use '"sbuffer"g:term_buf", but that didnt work
– Kristoffer
May 19 '16 at 14:24
|
show 1 more comment
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>
add a comment |
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>
add a comment |
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>
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>
edited Jun 1 '17 at 15:28
answered May 31 '17 at 0:11
user3762200user3762200
12719
12719
add a comment |
add a comment |
I Think this must be a little better more IDE Like,
let g:term_buf = 0
function! Term_toggle()
1wincmd w
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
rightbelow new
12winc -
try
exec "buffer ".g:term_buf
catch
call termopen("bash", "detach": 0)
let g:term_buf = bufnr("")
endtry
set laststatus=0
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
" Terminal go back to normal mode
tnoremap <Esc> <C-><C-n>
" When switching to terminal windows it goes into insert mode automatically
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
add a comment |
I Think this must be a little better more IDE Like,
let g:term_buf = 0
function! Term_toggle()
1wincmd w
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
rightbelow new
12winc -
try
exec "buffer ".g:term_buf
catch
call termopen("bash", "detach": 0)
let g:term_buf = bufnr("")
endtry
set laststatus=0
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
" Terminal go back to normal mode
tnoremap <Esc> <C-><C-n>
" When switching to terminal windows it goes into insert mode automatically
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
add a comment |
I Think this must be a little better more IDE Like,
let g:term_buf = 0
function! Term_toggle()
1wincmd w
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
rightbelow new
12winc -
try
exec "buffer ".g:term_buf
catch
call termopen("bash", "detach": 0)
let g:term_buf = bufnr("")
endtry
set laststatus=0
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
" Terminal go back to normal mode
tnoremap <Esc> <C-><C-n>
" When switching to terminal windows it goes into insert mode automatically
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
I Think this must be a little better more IDE Like,
let g:term_buf = 0
function! Term_toggle()
1wincmd w
if g:term_buf == bufnr("")
setlocal bufhidden=hide
close
else
rightbelow new
12winc -
try
exec "buffer ".g:term_buf
catch
call termopen("bash", "detach": 0)
let g:term_buf = bufnr("")
endtry
set laststatus=0
startinsert!
endif
endfunction
nnoremap <f4> :call Term_toggle()<cr>
" Terminal go back to normal mode
tnoremap <Esc> <C-><C-n>
" When switching to terminal windows it goes into insert mode automatically
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
answered Nov 26 '16 at 18:10
pyros2097pyros2097
14518
14518
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
add a comment |
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
I like this better, however it still generates a lot of these empty buffers as well.
– Kristoffer
Apr 27 '17 at 11:52
add a comment |
An simple solution, but it deletes the buffer:
nnoremap <silent> <F3> :split term://zsh <CR>
tnoreamp <silent> <F3> <C-><C-n> :bd! <CR>
autocmd TermOpen * startinsert
the terminal buffer needs to be selected to be closed!
add a comment |
An simple solution, but it deletes the buffer:
nnoremap <silent> <F3> :split term://zsh <CR>
tnoreamp <silent> <F3> <C-><C-n> :bd! <CR>
autocmd TermOpen * startinsert
the terminal buffer needs to be selected to be closed!
add a comment |
An simple solution, but it deletes the buffer:
nnoremap <silent> <F3> :split term://zsh <CR>
tnoreamp <silent> <F3> <C-><C-n> :bd! <CR>
autocmd TermOpen * startinsert
the terminal buffer needs to be selected to be closed!
An simple solution, but it deletes the buffer:
nnoremap <silent> <F3> :split term://zsh <CR>
tnoreamp <silent> <F3> <C-><C-n> :bd! <CR>
autocmd TermOpen * startinsert
the terminal buffer needs to be selected to be closed!
answered Jun 9 '18 at 14:28
user9618012
add a comment |
add a comment |