Simple neovim plugin to toggle terminal splits
| lua/toggle-term | refact: rename height_ratio to ratio | |
| plugin | feat: complete split navigation keybindings | |
| LICENSE | feat: initial implementation | |
| README.md | refact: rename height_ratio to ratio | |
toggle-term.nvim
A minimalist Neovim plugin to toggle and manage terminal splits.
Features
- Toggle a persistent terminal buffer in a split
- Create new terminal buffer in new split
- Movement and resize for terinal split
- Configurable split direction, ratio, and keybindings
Installation
Manually
mkdir -p ${XDG_DATA_HOME}/nvim/site/pack/default/start/
cd ${XDG_DATA_HOME}/nvim/site/pack/default/start/
# clone from one of the mirrors
git clone https://github.com/gnuunixchad/toggle-term.nvim
git clone https://codeberg.org/unixchad/toggle-term.nvim
vim-plug
local vim = vim
local Plug = vim.fn['plug#']
vim.call('plug#begin')
Plug('gnunixchad/toggle-term.nvim')
vim.call('plug#end')
Usage
Commands
:TermToggleto toggle a persistent terminal split:TermNewto Open a new terminal split
Keybindings
Keybindings for both Normal and Terminal mode:
| Bindings | Action |
|---|---|
| Ctrl-Enter | Toggle a persistent terminal split |
| Ctrl-Shift-Enter | Open a new terminal split |
Keybindings for Terminal mode only:
| Bindings | Action |
|---|---|
| leader ESC | Enter Normal mode in a terminal split |
| leader q | Delete the focused terminal buffer |
| Ctrl-h | Focus the split on the left |
| Ctrl-j | Focus the split below |
| Ctrl-k | Focus the split above |
| Ctrl-l | Focus the split on the right |
| Ctrl-w y | Decrease split width |
| Ctrl-w u | Increase split height |
| Ctrl-w i | Decrease split height |
| Ctrl-w o | Increase split width |
Configuration
require('toggle-term').setup({
ratio = 1/3, -- or a float number like 0.25
direction = 'bottom', -- or 'top', 'left', 'right'
})
Default Keybindings
-- toggle and new terminal
vim.keymap.set('n', '<C-CR>', ':TermToggle<CR>', { silent = true })
vim.keymap.set('t', '<C-CR>', '<C-\\><C-n>:TermToggle<CR>', { silent = true })
vim.keymap.set('n', '<C-S-CR>', ':TermNew<CR>', { silent = true })
vim.keymap.set('t', '<C-S-CR>', '<C-\\><C-n>:TermNew<CR>', { silent = true })
-- unfocus and close terminal
vim.keymap.set('t', '<leader><ESC>', '<C-\\><C-n>', { noremap = true })
vim.keymap.set('t', '<leader>q', '<C-\\><C-n>:quit!<CR>', { noremap = true })
vim.keymap.set('t', '<C-q>', '<C-\\><C-n>:quit!<CR>', { noremap = true })
-- movement
vim.keymap.set('t', '<C-h>', '<C-\\><C-n>:wincmd h<CR>', { noremap = true })
vim.keymap.set('t', '<C-j>', '<C-\\><C-n>:wincmd j<CR>', { noremap = true })
vim.keymap.set('t', '<C-k>', '<C-\\><C-n>:wincmd k<CR>', { noremap = true })
vim.keymap.set('t', '<C-l>', '<C-\\><C-n>:wincmd l<CR>', { noremap = true })
-- resize
vim.keymap.set('t', '<C-w>y', '<C-\\><C-n>:vertical resize -2<CR>i', { noremap = true })
vim.keymap.set('t', '<C-w>u', '<C-\\><C-n>:resize +2<CR>i', { noremap = true })
vim.keymap.set('t', '<C-w>i', '<C-\\><C-n>:resize -2<CR>i', { noremap = true })
vim.keymap.set('t', '<C-w>o', '<C-\\><C-n>:vertical resize +2<CR>i', { noremap = true })