# HG changeset patch # User zegervdv # Date 1611349081 -3600 # Node ID 890fe7d01f19c68b90610cec94f4f4588612eda2 # Parent e89bdbc1a2dd6396606d02d4a63ab1213b952b34 Use toggleterm as more robust terminal integration diff -r e89bdbc1a2dd -r 890fe7d01f19 dot_config/nvim/config.lua --- 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 lua require'terminal'.toggle()" -vim.cmd "tnoremap :lua require'terminal'.toggle()" - -- LSP and Treesitter config local lsp = require'lspconfig' diff -r e89bdbc1a2dd -r 890fe7d01f19 dot_config/nvim/init.vim --- 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 g :call ToggleDiff() if has('nvim') - tnoremap tnoremap h tnoremap j tnoremap 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 diff -r e89bdbc1a2dd -r 890fe7d01f19 dot_config/nvim/lua/terminal.lua --- 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 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