Code Monkey home page Code Monkey logo

nvim-terminal's Introduction

nvim-terminal

Terminal plugin to open/toggle the terminals in Neovim

demo.mp4

Features

  • Toggle terminal window
  • Quick switching between multiple terminal buffers

Install the plugin

packer

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

-- 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 = '<leader>;',

    -- 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 = '<leader><leader>+',

    -- keymap to decrease the window width
    decrease_width_keymap = '<leader><leader>-',

    -- keymap to increase the window height
    increase_height_keymap = '<leader>+',

    -- keymap to decrease the window height
    decrease_height_keymap = '<leader>-',

    terminals = {
        -- keymaps to open nth terminal
        {keymap = '<leader>1'},
        {keymap = '<leader>2'},
        {keymap = '<leader>3'},
        {keymap = '<leader>4'},
        {keymap = '<leader>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

vim.api.nvim_set_keymap('n', '<leader>t', ':lua NTGlobal["terminal"]:toggle()<cr>', silent)
vim.api.nvim_set_keymap('n', '<leader>1', ':lua NTGlobal["terminal"]:open(1)<cr>', silent)
vim.api.nvim_set_keymap('n', '<leader>+', ':lua NTGlobal["window"]:change_height(2)<cr>', silent)
vim.api.nvim_set_keymap('n', '<leader>-', ':lua NTGlobal["window"]:change_height(-2)<cr>', silent)

PRO MODE

Default Terminal

terminal = require('nvim-terminal').DefaultTerminal;

local silent = { silent = true }

vim.api.nvim_set_keymap('n', '<leader>t', ':lua terminal:toggle()<cr>', silent)
vim.api.nvim_set_keymap('n', '<leader>1', ':lua terminal:open(1)<cr>', silent)
vim.api.nvim_set_keymap('n', '<leader>2', ':lua terminal:open(2)<cr>', silent)
vim.api.nvim_set_keymap('n', '<leader>3', ':lua terminal:open(3)<cr>', silent)

Customized Window

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)

nvim-terminal's People

Contributors

culot avatar s1n7ax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nvim-terminal's Issues

Respect embedded vim window resizing on toggle

Thank you for this awesome plugin!

Here is an improvement suggestion

Problem

Whenever you resize your windows with vim embedded resize function, you might expect your toggling terminal windows to respect this setting after closing and opening them again
(personally I even have these remaps:
nnoremap <Up> :resize -2<CR>
nnoremap <Down> :resize +2<CR>).

Now, whenever Window.close is executed, it doesn't memoize window's width and height.
Next time Window.open is executed, it opens with its default settings

Solution

I tweaked it by modifying the Window.close function:

function Window:close(winid)
    if self:is_valid() then 
        self.width = v.nvim_win_get_width(self.windid)
        self.height = v.nvim_win_get_height(self.winid)
        v.nvim_win_close(self.winid, false) 
    end
end

My proposition is either to embed it as default behaviour or to make a setting for it

Cannont exit terminal

I am using Neovim 0.7.2 and have installed Neovim-Terminal using Packer. I can open the terminal using + 1 or any other method. I can also toggle it. However, when I move to insert mode, I cannot switch between panes or even press [ESC]. I have to execute exit to close the terminal. I use Bash for my terminal. Please help me.

Add support for custom init commands

We can pass a command to the interactive shell using :terminal [{cmd}] in Neovim. It would be possible to add command arguments to run in the shell when opening a new terminal.

Something like this where you can define various commands in a more organised way would be superb:

require("nvim-terminal").setup {
	init_commands = {
		"clear",
                "echo 'hello world'",
                "export ABC='ABC'"
	}
}

This is very useful for setting up the shell to work with it inside Neovim.

Reuse same terminal after nvim restart

When I leave the terminal open and quit nvim with :qa and restart nvim. I got the same terminal, but the default toggle binds to a new terminal, so it will open two terminals. It would be nice to have the defaul toggle reattach to the same terminal.

abc

Prettify Terminals

When terminals buffer gets created would be nice to have set buflisted() to false and some buffer/window options e.g. number, relativenumber, foldcolumn to false / other values that correspond to disabled state

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.