🆕 ➡️ See new version written in lua: /~https://github.com/caenrique/buffer-term.nvim
Toggle terminal buffer or create new one if there is none. It keeps the shell session between toggles.
You have to set your own key bindings. For example:
nnoremap <silent> <C-z> :ToggleTerminal<Enter>
tnoremap <silent> <C-z> <C-\><C-n>:ToggleTerminal<Enter>
Command | Description |
---|---|
:ToggleTerminal | Toggles a terminal which is the same shell instance regardless of where it is called |
:ToggleTabTerminal | Toggles a tab specific terminal instance. It will have a different shell session for each tab |
:ToggleWindowTerminal | Toggles a window specific terminal instance. It will have a different shell session for each window |
Setting | Description | Default |
---|---|---|
g:preserve_alternate_buffer | Preserve the alternate_buffer of the current window when opening and closing the terminal | 1 |
g:auto_start_insert | enter insert mode automatically when given focus. Uses BufEnter event | 0 |
g:open_in_insert_mode | start in insert mode when you open the terminal. Uses BufWinEnter event | 1 |
Use your favourite plugin manager. For example, using Plug:
call plug#begin()
Plug 'caenrique/nvim-toggle-terminal'
call plug#end()
Some extra setting that can be used in conjuction with this plugin for convenience:
Make your life easier by mapping ESC in terminal mode. And if you use fzf, this will not break the ESC behaviour:
tnoremap <expr> <Esc> (&filetype == "fzf") ? "<Esc>" : "<c-\><c-n>"
Use this to switch back and forth between files and terminal without the anoying No write since last change (add ! to override)
message with unsaved changes:
set autowriteall
Use nvr to avoid nesting nvim in Terminal buffers. This should go in your .bashrc
or similar:
nvim_wrapper() {
NVIM=`which nvim`
if test -z $NVIM_LISTEN_ADDRESS; then
$NVIM $@
else
if test -z $@; then
nvr -l -c new
else
nvr -l $@
fi
fi
}
alias nvim="nvim_wrapper"