2

I want to make toggleable window with terminal buffer similar to every IDE terminal feature.


Currently i have mapped:

noremap <F4> :botright 8split term://bash<CR>
tnoremap <F4> <C-\><C-n>:q<CR>
autocmd BufEnter term://* startinsert | set wfh

but buffer is lost whenever is not active on any window (ex. on :q)


EDIT And how to reopen the same buffer whenever it already eixsts instead of creating new one every time?

Mesco
  • 466
  • 6
  • 12
  • 1
    duplicate of my own question here https://vi.stackexchange.com/questions/19276/how-to-keep-the-neovim-terminal-buffer-in-the-buffer-list-even-after-it-being-hi – 3N4N Mar 23 '19 at 10:22
  • 1
    And thanks for :h wfh, I didn't think there was something like that built in. Nice one! – 3N4N Mar 23 '19 at 10:23
  • And try to wrap autocmd's in augroup. Check here for why. – 3N4N Mar 23 '19 at 10:26
  • thanks! But :h terminal says: 'bufhidden' defaults to "hide", so I didin't try myself – Mesco Mar 23 '19 at 10:32
  • Oh, it does, doesn't it? But check, after launching nvim with nvim -u NORC and opening terminal with :term and then check :set bufhidden?. I see bufhidden=, so not defaults to hide. Must be a bug. What do you see? We might need to notify neovim community to edit their help documents! – 3N4N Mar 23 '19 at 10:39
  • As for "How to reopen the same terminal buffer", I would recommend adopting to a workflow where you only need one terminal buffer. If you can, then, you just bind your toggling key to check if any terminal buffer exists by checking for "term://" in it's bufname. I will try to provide a complete answer if you want. – 3N4N Mar 23 '19 at 10:41

2 Answers2

3

Now vim has :term built in, not just in neo vim. So you can use that and then to hide it use CTRL-W :hide

I got this from :help terminal (as suggested in the comments above):

You can use CTRL-W :hide to close the terminal window and make the buffer   
hidden, the job keeps running.  The :buffer command can be used to turn the 
current window into a terminal window.  If there are unsaved changes this   
fails, use ! to force, as usual.                                            

There's lots of buffer commands (see :help buffer-list) but :unhide seems to work nicely for this to bring it back.

Fsmv
  • 131
  • 3
0

Check this post Or use this gist directly.

Rocky
  • 101
  • 1
  • 2
    Can you expand your answer so it's not likely to succumb to link rot? – Heptite Nov 09 '22 at 21:59
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Nov 09 '22 at 22:34