From dcda21f8244887cbbe1dd31832896d2fd12d9d57 Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Tue, 17 Sep 2024 11:32:59 +0000 Subject: [PATCH] feat(nvim): migrate from toggleterm to slimux (#73) Instead of using the native terminal available in `neovim` and the [toggleterm][0] extension, I'm migrating to [slimux][1] and `tmux` to share commands between terminals. Co-authored-by: Joao P Dubas Reviewed-on: https://gitea.dubas.dev/joao.dubas/ide/pulls/73 [0]: https://github.com/akinsho/toggleterm.nvim [1]: https://github.com/EvWilson/slimux.nvim Co-authored-by: Joao P Dubas Co-committed-by: Joao P Dubas --- Dockerfile | 2 +- config/nvim/lua/custom/plugins/init.lua | 127 +++++------------------- patch/kickstart.nvim/updates.patch | 22 ++-- 3 files changed, 36 insertions(+), 115 deletions(-) diff --git a/Dockerfile b/Dockerfile index e191791..18da2f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -183,7 +183,7 @@ COPY ./patch/kickstart.nvim/updates.patch /tmp COPY ./config/nvim/lua/custom/plugins/init.lua /tmp RUN git clone https://github.com/nvim-lua/kickstart.nvim.git "${XDG_CONFIG_HOME}"/nvim \ && cd ${XDG_CONFIG_HOME}/nvim \ - && git reset --hard 186018483039b20dc39d7991e4fb28090dd4750e \ + && git reset --hard 7201dc480134f41dd1be1f8f9b8f8470aac82a3b \ && git apply /tmp/updates.patch \ && cp /tmp/init.lua ${XDG_CONFIG_HOME}/nvim/lua/custom/plugins \ && nvim --headless "+Lazy! sync" +qa diff --git a/config/nvim/lua/custom/plugins/init.lua b/config/nvim/lua/custom/plugins/init.lua index 9634f5b..0fdfaa2 100644 --- a/config/nvim/lua/custom/plugins/init.lua +++ b/config/nvim/lua/custom/plugins/init.lua @@ -104,82 +104,19 @@ return { priority = 1000, config = true, }, - -- { - -- 'rest-nvim/rest.nvim', - -- dependencies = { 'luarocks.nvim' }, - -- ft = { - -- 'http', - -- 'rest', - -- }, - -- config = function() - -- require('rest-nvim').setup { - -- client = 'curl', - -- custom_dynamic_variables = {}, - -- encode_url = true, - -- env_file = '.env', - -- skip_ssl_verification = false, - -- highlight = { - -- enable = true, - -- timeout = 15, - -- }, - -- result = { - -- behavior = { - -- decode_url = true, - -- formatters = { - -- json = 'jq', - -- html = false, - -- }, - -- show_info = { - -- curl_command = true, - -- headers = true, - -- http_info = true, - -- url = true, - -- }, - -- statistics = { - -- enable = true, - -- stats = { - -- { 'total_time', title = 'Time taken:' }, - -- { 'size_download_t', title = 'Download size:' }, - -- }, - -- }, - -- }, - -- split = { - -- horizontal = false, - -- in_place = false, - -- }, - -- }, - -- } - -- end, - -- keys = function() - -- local status_ok, which_key = pcall(require, 'which-key') - -- if status_ok then - -- which_key.register { - -- ['t'] = { name = 'Res[t]', _ = 'which_key_ignore' }, - -- } - -- end - -- return { - -- { 'tr', 'Rest run', desc = 'Run the request under cursor' }, - -- { - -- 'tp', - -- 'RestNvimPreview', - -- desc = 'Preview the curl command for the request under cursor', - -- }, - -- { 'tl', 'Rest run last', desc = 'Re-run the last request' }, - -- } - -- end, - -- }, { - 'akinsho/toggleterm.nvim', - opts = { - size = vim.o.lines * 0.75, - open_mapping = [[]], - hide_numbers = true, - shade_filetypes = {}, - shade_terminals = true, - shading_factor = 2, - direction = 'horizontal', - shell = vim.o.shell, - }, + 'EvWilson/slimux.nvim', + lazy = true, + opts = function() + local status_ok, slimux = pcall(require, 'slimux') + if not status_ok then + return {} + end + return { + target_socket = slimux.get_tmux_socket(), + target_pane = string.format('%s.1', slimux.get_tmux_window()), + } + end, keys = function() local status_ok, which_key = pcall(require, 'which-key') if status_ok then @@ -187,38 +124,22 @@ return { { 'm', group = 'Toggle ter[m]inal' }, } end - vim.api.nvim_create_autocmd('TermOpen', { - group = vim.api.nvim_create_augroup('kickstart-custom-term-open-mapping', { clear = true }), - callback = function(args) - local bufnr = args.buf - local opts = { buffer = bufnr } - vim.keymap.set('t', '', [[]], opts) - vim.keymap.set('t', 'jk', [[]], opts) - vim.keymap.set('t', '', [[wincmd h]], opts) - vim.keymap.set('t', '', [[wincmd j]], opts) - vim.keymap.set('t', '', [[wincmd k]], opts) - vim.keymap.set('t', '', [[wincmd l]], opts) - vim.keymap.set('t', '', [[]], opts) - end, - }) + local slimux_status_ok, slimux = pcall(require, 'slimux') + if not slimux_status_ok then + return {} + end return { { - 'mh', - 'ToggleTerm direction=horizontal size=' .. tostring(vim.o.lines * 0.75) .. '', - desc = 'Open ter[m]inal [h]orizontally', - noremap = true, + 'xr', + slimux.send_highlighted_text, + mode = 'v', + desc = 'Send currently highlighted text to configured tmux pane', }, { - 'mv', - 'ToggleTerm direction=vertical size=' .. tostring(vim.o.columns * 0.5) .. '', - desc = 'Open ter[m]inal [v]ertically', - noremap = true, - }, - { - 'mc', - 'ToggleTermSendCurrentLine', - desc = 'Send [c]urrent line under the cursor', - noremap = true, + 'r', + slimux.send_paragraph_text, + mode = 'n', + desc = 'Send paragraph under cursor to configured tmux pane', }, } end, diff --git a/patch/kickstart.nvim/updates.patch b/patch/kickstart.nvim/updates.patch index 0d5d776..1442cfd 100644 --- a/patch/kickstart.nvim/updates.patch +++ b/patch/kickstart.nvim/updates.patch @@ -1,5 +1,5 @@ diff --git a/init.lua b/init.lua -index 220d304..62a9702 100644 +index ea86b79..93250ab 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' @@ -39,8 +39,8 @@ index 220d304..62a9702 100644 -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` -@@ -582,6 +590,28 @@ require('lazy').setup({ - -- tsserver = {}, +@@ -618,6 +626,28 @@ require('lazy').setup({ + -- ts_ls = {}, -- + cuelsp = {}, @@ -68,7 +68,7 @@ index 220d304..62a9702 100644 lua_ls = { -- cmd = {...}, -- filetypes = { ...}, -@@ -596,6 +626,33 @@ require('lazy').setup({ +@@ -632,6 +662,33 @@ require('lazy').setup({ }, }, }, @@ -76,7 +76,7 @@ index 220d304..62a9702 100644 + r_language_server = {}, + templ = {}, + terraformls = {}, -+ tsserver = {}, ++ ts_ls = {}, + yamlls = { + settings = { + yaml = { @@ -102,9 +102,9 @@ index 220d304..62a9702 100644 } -- Ensure the servers and tools above are installed -@@ -622,6 +679,33 @@ require('lazy').setup({ +@@ -658,6 +715,33 @@ require('lazy').setup({ -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for tsserver) + -- certain features of an LSP (for example, turning off formatting for ts_ls) server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + -- overwrite elixirls for older versions of elixir + -- * elixir 1.11 use version 0.12.0 @@ -136,9 +136,9 @@ index 220d304..62a9702 100644 require('lspconfig')[server_name].setup(server) end, }, -@@ -844,7 +928,39 @@ require('lazy').setup({ - 'nvim-treesitter/nvim-treesitter', - build = ':TSUpdate', +@@ -888,7 +972,39 @@ require('lazy').setup({ + main = 'nvim-treesitter.configs', -- Sets main module to use for opts + -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + ensure_installed = { @@ -177,7 +177,7 @@ index 220d304..62a9702 100644 -- Autoinstall languages that are not installed auto_install = true, highlight = { -@@ -881,18 +997,18 @@ require('lazy').setup({ +@@ -918,18 +1034,18 @@ require('lazy').setup({ -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- -- require 'kickstart.plugins.debug',