https://github.com/s1n7ax/nvim-terminal
A Lua-Neovim plugin that toggles a terminal
https://github.com/s1n7ax/nvim-terminal
lua neovim neovim-plugin nvim
Last synced: 3 months ago
JSON representation
A Lua-Neovim plugin that toggles a terminal
- Host: GitHub
- URL: https://github.com/s1n7ax/nvim-terminal
- Owner: s1n7ax
- License: mit
- Created: 2021-01-28T07:33:32.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-06-29T17:03:31.000Z (over 3 years ago)
- Last Synced: 2025-03-11T12:42:05.031Z (9 months ago)
- Topics: lua, neovim, neovim-plugin, nvim
- Language: Lua
- Homepage:
- Size: 5.15 MB
- Stars: 117
- Watchers: 2
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim-sorted - s1n7ax/nvim-terminal - Neovim plugin that toggles a terminal | (Terminal Integration)
- awesome-neovim - s1n7ax/nvim-terminal - A simple & easy to use multi-terminal plugin. (Terminal Integration / CSV Files)
README
# nvim-terminal
Terminal plugin to open/toggle the terminals in Neovim
https://user-images.githubusercontent.com/18459807/129582749-2e732591-cb8d-4cb8-a427-9da0c79a621d.mp4
## Features
* Toggle terminal window
* Quick switching between multiple terminal buffers
## Install the plugin
**packer**
```lua
use {
's1n7ax/nvim-terminal',
config = function()
vim.o.hidden = true
require('nvim-terminal').setup()
end,
}
```
## Default Keymaps
leader + ; - **Toggle open/close terminal**
leader + 1 - **Open terminal 1**
leader + 2 - **Open terminal 2**
leader + 3 - **Open terminal 3**
leader + 4 - **Open terminal 4**
leader + 5 - **Open terminal 5**
leader + + - **Increase window height**
leader + - - **Decrease window height**
leader + leader + + - **Increase window width**
leader + leader + - - **Decrease window width**
## Configuration
Simply pass the custom configuration to `setup` method
```lua
-- following option will hide the buffer when it is closed instead of deleting
-- the buffer. This is important to reuse the last terminal buffer
-- IF the option is not set, plugin will open a new terminal every single time
vim.o.hidden = true
require('nvim-terminal').setup({
window = {
-- Do `:h :botright` for more information
-- NOTE: width or height may not be applied in some "pos"
position = 'botright',
-- Do `:h split` for more information
split = 'sp',
-- Width of the terminal
width = 50,
-- Height of the terminal
height = 15,
},
-- keymap to disable all the default keymaps
disable_default_keymaps = false,
-- keymap to toggle open and close terminal window
toggle_keymap = ';',
-- increase the window height by when you hit the keymap
window_height_change_amount = 2,
-- increase the window width by when you hit the keymap
window_width_change_amount = 2,
-- keymap to increase the window width
increase_width_keymap = '+',
-- keymap to decrease the window width
decrease_width_keymap = '-',
-- keymap to increase the window height
increase_height_keymap = '+',
-- keymap to decrease the window height
decrease_height_keymap = '-',
terminals = {
-- keymaps to open nth terminal
{keymap = '1'},
{keymap = '2'},
{keymap = '3'},
{keymap = '4'},
{keymap = '5'},
},
})
```
## Add Keymaps Manually
`nvim-terminal` adds a global variable called `NTGlobal`. When you call
`require('nvim-terminal').setup()` it adds `terminal` and `window` properties to
`NTGlobal`
```lua
vim.api.nvim_set_keymap('n', 't', ':lua NTGlobal["terminal"]:toggle()', silent)
vim.api.nvim_set_keymap('n', '1', ':lua NTGlobal["terminal"]:open(1)', silent)
vim.api.nvim_set_keymap('n', '+', ':lua NTGlobal["window"]:change_height(2)', silent)
vim.api.nvim_set_keymap('n', '-', ':lua NTGlobal["window"]:change_height(-2)', silent)
```
## PRO MODE
### Default Terminal
```lua
terminal = require('nvim-terminal').DefaultTerminal;
local silent = { silent = true }
vim.api.nvim_set_keymap('n', 't', ':lua terminal:toggle()', silent)
vim.api.nvim_set_keymap('n', '1', ':lua terminal:open(1)', silent)
vim.api.nvim_set_keymap('n', '2', ':lua terminal:open(2)', silent)
vim.api.nvim_set_keymap('n', '3', ':lua terminal:open(3)', silent)
```
### Customized Window
```lua
local Terminal = require('nvim-terminal.terminal')
local Window = require('nvim-terminal.window')
local window = Window:new({
position = 'botright',
split = 'sp',
width = 50,
height = 15
})
terminal = Terminal:new(window)
```