Mercurial > dotfiles
changeset 338:890fe7d01f19
Use toggleterm as more robust terminal integration
author | zegervdv <zegervdv@me.com> |
---|---|
date | Fri, 22 Jan 2021 21:58:01 +0100 |
parents | e89bdbc1a2dd |
children | 308594cabf62 |
files | dot_config/nvim/config.lua dot_config/nvim/init.vim dot_config/nvim/lua/terminal.lua |
diffstat | 3 files changed, 13 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/dot_config/nvim/config.lua Thu Jan 21 10:16:25 2021 +0100 +++ b/dot_config/nvim/config.lua Fri Jan 22 21:58:01 2021 +0100 @@ -109,9 +109,21 @@ -- Colorscheme use {'zegervdv/nvcode-color-schemes.vim'} + -- Terminal + use {'akinsho/nvim-toggleterm.lua'} + end) end +require'toggleterm'.setup { + size = 20, + open_mapping = [[+]], + shade_filetypes = {}, + shade_terminals = true, + persist_size = true, + direction = 'horizontal', +} + -- This came from https://github.com/tjdevries/config_manager/blob/master/xdg_config/nvim/lua/lsp_config.lua local mapper = function(mode, key, result, noremap) if noremap == nil then @@ -120,10 +132,6 @@ vim.fn.nvim_buf_set_keymap(0, mode, key, result, {noremap=noremap, silent=true}) end --- Terminal -vim.cmd "nnoremap <silent> <c-z> <cmd>lua require'terminal'.toggle()<CR>" -vim.cmd "tnoremap <silent> <c-z> <c-\\><c-n>:lua require'terminal'.toggle()<CR>" - -- LSP and Treesitter config local lsp = require'lspconfig'
--- a/dot_config/nvim/init.vim Thu Jan 21 10:16:25 2021 +0100 +++ b/dot_config/nvim/init.vim Fri Jan 22 21:58:01 2021 +0100 @@ -391,7 +391,6 @@ nnoremap <leader>g :call ToggleDiff()<CR> if has('nvim') - tnoremap <space><esc> <C-\><C-n> tnoremap <C-h> <C-\><C-n><C-w>h tnoremap <C-j> <C-\><C-n><C-w>j tnoremap <C-k> <C-\><C-n><C-w>k @@ -400,6 +399,7 @@ au! au BufEnter * if &buftype == 'terminal' | :startinsert | endif augroup END + let $GIT_EDITOR = 'nvr -cc split --remote-wait' endif " Open buffers, tags... in vertical splits
--- a/dot_config/nvim/lua/terminal.lua Thu Jan 21 10:16:25 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ --- Copied from: https://github.com/kutsan/dotfiles/blob/b2046a6c0bcc754fc381351119c14c374721fd4d/.config/nvim/lua/kutsan/mappings/normal/terminal.lua - -local api = vim.api -local fn = vim.fn - -local terminal = { - buf = nil, - win = nil, - pid = nil -} - -terminal.open = function () - -- Create buffer. - local buf = nil - - if terminal.buf and api.nvim_buf_is_loaded(terminal.buf) then - buf = terminal.buf - else - buf = api.nvim_create_buf(false, true) - end - - -- Create window. - local width = math.ceil(vim.o.columns * 0.8) - local height = math.ceil(vim.o.lines * 0.9) - - local win = api.nvim_open_win(buf, true, { - relative = 'editor', - style = 'minimal', - width = width, - height = height, - col = math.ceil((vim.o.columns - width) / 2), - row = math.ceil((vim.o.lines - height) / 2 - 1), - }) - api.nvim_win_set_option(win, 'winhighlight', 'Normal:CursorLine') - - -- Launch terminal. - if not terminal.buf then - terminal.pid = fn.termopen(string.format('%s --login', os.getenv('SHELL'))) - end - - vim.cmd('startinsert') - vim.cmd("autocmd! TermClose <buffer> lua require('terminal').close(true)") - - -- Save current handles. - terminal.win = win - terminal.buf = buf -end - -terminal.close = function (force) - if not terminal.win then - return - end - - if api.nvim_win_is_valid(terminal.win) then - api.nvim_win_close(terminal.win, false) - terminal.win = nil - end - - -- Force close upon terminal exit. - if force then - if api.nvim_buf_is_loaded(terminal.buf) then - api.nvim_buf_delete(terminal.buf, { force = true }) - end - - fn.jobstop(terminal.pid) - - terminal.buf = nil - terminal.pid = nil - end -end - -terminal.toggle = function () - if not terminal.win then - terminal.open() - else - terminal.close() - end -end - -return terminal