From 6e3a38a7221b869b57953005121bc401856c5549 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Sat, 15 Mar 2025 05:28:45 -0400 Subject: [PATCH] more solid nvim clipboard inside tmux --- .config/nvim/lazy-lock.json | 35 ++-- .config/nvim/lua/kamu/clipboard.lua | 43 +++++ .config/nvim/lua/kamu/init.lua | 2 +- .config/nvim/lua/kamu/keymaps.lua | 13 +- .config/nvim/lua/kamu/options.lua | 35 +--- .config/nvim/lua/kamu/plugins/completions.lua | 31 +--- .config/nvim/lua/kamu/plugins/lsp.lua | 163 +++++++++++------- .config/nvim/lua/kamu/plugins/snacks.lua | 34 +--- .config/nvim/lua/kamu/plugins/treesitter.lua | 1 - 9 files changed, 178 insertions(+), 179 deletions(-) create mode 100644 .config/nvim/lua/kamu/clipboard.lua diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index b45e5ae..965237b 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,26 +1,27 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, - "blink.cmp": { "branch": "main", "commit": "bff6c0f06bdc1114c5816b0f6b19ad6a7e15a638" }, - "catppuccin": { "branch": "main", "commit": "faf15ab0201b564b6368ffa47b56feefc92ce3f4" }, + "blink.cmp": { "branch": "main", "commit": "b6f11a0aa33e601c469a126e3ed6e35208fe3ea3" }, + "catppuccin": { "branch": "main", "commit": "0b2437bcc12b4021614dc41fcea9d0f136d94063" }, "friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" }, - "lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" }, - "lazydev.nvim": { "branch": "main", "commit": "f59bd14a852ca43db38e3662395354cb2a9b13e0" }, - "lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "2daa8921b7afdcfa47419a21ea343c3df6d74fa0" }, + "lazy.nvim": { "branch": "main", "commit": "f15a93907ddad3d9139aea465ae18336d87f5ce6" }, + "lazydev.nvim": { "branch": "main", "commit": "a1b78b2ac6f978c72e76ea90ae92a94edf380cfc" }, + "lualine.nvim": { "branch": "master", "commit": "f4f791f67e70d378a754d02da068231d2352e5bc" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "805c31ec6bfb557975143712ecff6956d3227141" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, - "mini.icons": { "branch": "main", "commit": "44c0160526f7ae17ca8e8eab9ab235d047fcf7a6" }, - "noice.nvim": { "branch": "main", "commit": "eaed6cc9c06aa2013b5255349e4f26a6b17ab70f" }, + "mini.icons": { "branch": "main", "commit": "ec61af6e606fc89ee3b1d8f2f20166a3ca917a36" }, + "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, "nui.nvim": { "branch": "main", "commit": "53e907ffe5eedebdca1cd503b00aa8692068ca46" }, - "nvim-highlight-colors": { "branch": "main", "commit": "e967e2ba13fd4ca731b41d0e5cc1ac2edcd6e25e" }, - "nvim-lspconfig": { "branch": "master", "commit": "040001d85e9190a904d0e35ef5774633e14d8475" }, + "nvim-highlight-colors": { "branch": "main", "commit": "16a3cd4a32a655c8537de6e5643c234a9b38183a" }, + "nvim-lspconfig": { "branch": "master", "commit": "6c17f8656f667727b27f5f598463afedb7791b18" }, "nvim-scrollbar": { "branch": "main", "commit": "6994eb9f73d5fdc36ee2c8717940e8c853e51a49" }, - "nvim-treesitter": { "branch": "master", "commit": "2405274937718d520a40e03df92030dca6b4f0fd" }, - "nvim-web-devicons": { "branch": "master", "commit": "0eb18da56e2ba6ba24de7130a12bcc4e31ad11cb" }, - "oil.nvim": { "branch": "master", "commit": "dba037598843973b8c54bc5ce0318db4a0da439d" }, - "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, - "snacks.nvim": { "branch": "main", "commit": "98df370703b3c47a297988f3e55ce99628639590" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" }, + "nvim-treesitter": { "branch": "master", "commit": "6d957c22cb48a734b009a69d03c18d20042c4754" }, + "nvim-web-devicons": { "branch": "master", "commit": "1020869742ecb191f260818234517f4a1515cfe8" }, + "oil.nvim": { "branch": "master", "commit": "32dd3e378d47673679e76a773451f82f971a66df" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "rustaceanvim": { "branch": "master", "commit": "2b0f0b7e03751cf8ed123322f9b02d8f73fa9df7" }, + "snacks.nvim": { "branch": "main", "commit": "121e74e4a5b7962ee370a8d8ae75d1c7b4c2e11c" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "2a5ceff981501cff8f46871d5402cd3378a8ab6a" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "vim-tmux-navigator": { "branch": "master", "commit": "424b5caa154bff34dc258ee53cec5a8e36cf7ea8" } + "vim-tmux-navigator": { "branch": "master", "commit": "d847ea942a5bb4d4fab6efebc9f30d787fd96e65" } } diff --git a/.config/nvim/lua/kamu/clipboard.lua b/.config/nvim/lua/kamu/clipboard.lua new file mode 100644 index 0000000..68ea6c6 --- /dev/null +++ b/.config/nvim/lua/kamu/clipboard.lua @@ -0,0 +1,43 @@ +-- https://mitchellt.com/2022/05/15/WSL-Neovim-Lua-and-the-Windows-Clipboard.html +if os.getenv('WSL_DISTRO_NAME') ~= nil then + vim.g.clipboard = { + name = 'wsl clipboard', + copy = { + ["+"] = { "clip.exe" }, + ["*"] = { "clip.exe" } + }, + paste = { + ["+"] = { 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))' }, + ["*"] = { 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))' } + }, + cache_enabled = true + } +elseif vim.env.TMUX ~= nil then + local copy = { 'tmux', 'load-buffer', '-w', '-' } + local paste = { 'bash', '-c', 'tmux refresh-client -l && sleep 0.05 && tmux save-buffer -' } + vim.g.clipboard = { + name = 'tmux', + copy = { + ['+'] = copy, + ['*'] = copy, + }, + paste = { + ['+'] = paste, + ['*'] = paste, + }, + cache_enabled = 0, + } +else + vim.g.clipboard = { + name = 'OSC 52', + copy = { + ['+'] = require('vim.ui.clipboard.osc52').copy('+'), + ['*'] = require('vim.ui.clipboard.osc52').copy('*'), + }, + paste = { + ['+'] = require('vim.ui.clipboard.osc52').paste('+'), + ['*'] = require('vim.ui.clipboard.osc52').paste('*'), + }, + cache_enabled = true + } +end diff --git a/.config/nvim/lua/kamu/init.lua b/.config/nvim/lua/kamu/init.lua index 0f859df..c3f2a93 100644 --- a/.config/nvim/lua/kamu/init.lua +++ b/.config/nvim/lua/kamu/init.lua @@ -1,7 +1,7 @@ vim.g.mapleader = ' ' +require("kamu.clipboard") require("kamu.options") --require("kamu.commands") require("kamu.lazy") require("kamu.keymaps") - diff --git a/.config/nvim/lua/kamu/keymaps.lua b/.config/nvim/lua/kamu/keymaps.lua index 145ad1d..fb11b38 100644 --- a/.config/nvim/lua/kamu/keymaps.lua +++ b/.config/nvim/lua/kamu/keymaps.lua @@ -21,11 +21,8 @@ vim.keymap.set("n", "x", "source %") vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") --- Highlight when yanking text -vim.api.nvim_create_autocmd("TextYankPost", { - desc = "Highlight when yanking text", - group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) +-- copy to system clipboard +vim.keymap.set("v", "y", "\"+y") +vim.keymap.set("n", "y", "\"+y") +vim.keymap.set("v", "p", "\"+p") +vim.keymap.set("n", "p", "\"+p") diff --git a/.config/nvim/lua/kamu/options.lua b/.config/nvim/lua/kamu/options.lua index 315d6b9..252c9fc 100644 --- a/.config/nvim/lua/kamu/options.lua +++ b/.config/nvim/lua/kamu/options.lua @@ -1,35 +1,3 @@ -local in_wsl = os.getenv('WSL_DISTRO_NAME') ~= nil - --- https://mitchellt.com/2022/05/15/WSL-Neovim-Lua-and-the-Windows-Clipboard.html -if in_wsl then - vim.g.clipboard = { - name = 'wsl clipboard', - copy = { - ["+"] = { "clip.exe" }, - ["*"] = { "clip.exe" } - }, - paste = { - ["+"] = { 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))' }, - ["*"] = { 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))' } }, - cache_enabled = true - } -end - --- if in_wsl then --- vim.g.clipboard = { --- name = 'WslClipboard', --- copy = { --- ['+'] = 'clip.exe', --- ['*'] = 'clip.exe', --- }, --- paste = { --- ['+'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', --- ['*'] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))', --- }, --- cache_enabled = false, --- } --- end - -- Highlight on Yank vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking text", @@ -88,10 +56,9 @@ local options = { inccommand = 'split', cursorline = true, --- guicursor = "a:block" + -- guicursor = "a:block" } for option, value in pairs(options) do vim.opt[option] = value end - diff --git a/.config/nvim/lua/kamu/plugins/completions.lua b/.config/nvim/lua/kamu/plugins/completions.lua index c5e7107..4c996fd 100644 --- a/.config/nvim/lua/kamu/plugins/completions.lua +++ b/.config/nvim/lua/kamu/plugins/completions.lua @@ -14,8 +14,10 @@ return { }, }, }, - build = 'cargo build --release', + version = '*', + -- build = 'cargo build --release', opts = { + snippets = { preset = 'luasnip' }, keymap = { preset = 'super-tab' }, appearance = { use_nvim_cmp_as_default = true, @@ -41,16 +43,16 @@ return { }, }, ghost_text = { - enabled = true + enabled = false } }, signature = { enabled = true }, sources = { - default = { 'lsp', 'path', 'luasnip', 'buffer' }, + default = { 'lsp', 'path', 'snippets', 'buffer' }, -- TODO: add cmp-emoji as another cmp source -- needs https://github.com/Saghen/blink.compat per_filetype = { - tex = { 'lsp', 'path', 'luasnip', 'buffer' }, - lua = { 'lsp', 'path', 'luasnip', 'buffer', 'lazydev' }, + tex = { 'lsp', 'path', 'snippets', 'buffer' }, + lua = { 'lsp', 'path', 'snippets', 'buffer', 'lazydev' }, }, providers = { lazydev = { @@ -58,27 +60,8 @@ return { module = "lazydev.integrations.blink", fallbacks = { "lsp" }, }, - luasnip = { - - name = 'Luasnip', - module = 'blink.cmp.sources.luasnip', - opts = { - use_show_condition = true, - show_autosnippets = true, - } - }, }, }, - snippets = { - expand = function(snippet) require('luasnip').lsp_expand(snippet) end, - active = function(filter) - if filter and filter.direction then - return require('luasnip').jumpable(filter.direction) - end - return require('luasnip').in_snippet() - end, - jump = function(direction) require('luasnip').jump(direction) end, - }, }, config = function(_, opts) diff --git a/.config/nvim/lua/kamu/plugins/lsp.lua b/.config/nvim/lua/kamu/plugins/lsp.lua index 99cb372..79076f2 100644 --- a/.config/nvim/lua/kamu/plugins/lsp.lua +++ b/.config/nvim/lua/kamu/plugins/lsp.lua @@ -1,78 +1,109 @@ return { - -- lsp client plugin - "neovim/nvim-lspconfig", -- https://github.com/neovim/nvim-lspconfig - dependencies = { - "williamboman/mason.nvim", -- https://github.com/williamboman/mason.nvim - "williamboman/mason-lspconfig.nvim", -- https://github.com/williamboman/mason-lspconfig.nvim bridges the gab between lspconfig and mason - 'saghen/blink.cmp', - }, - config = function() - local capabilities = require('blink.cmp').get_lsp_capabilities() + { + -- lsp client plugin + "neovim/nvim-lspconfig", -- https://github.com/neovim/nvim-lspconfig + dependencies = { + "williamboman/mason.nvim", -- https://github.com/williamboman/mason.nvim + "williamboman/mason-lspconfig.nvim", -- https://github.com/williamboman/mason-lspconfig.nvim bridges the gab between lspconfig and mason + 'saghen/blink.cmp', + }, + config = function() + local capabilities = require('blink.cmp').get_lsp_capabilities() - require('mason').setup() - require('mason-lspconfig').setup({ - ensure_installed = { - 'lua_ls', - 'astro', - 'ansiblels', - }, - handlers = { - function(server_name) - require("lspconfig")[server_name].setup({ - capabilities = capabilities - }) - end, + require('mason').setup() + require('mason-lspconfig').setup({ + ensure_installed = { + 'lua_ls', + }, + handlers = { + function(server_name) + require("lspconfig")[server_name].setup({ + capabilities = capabilities + }) + end, - ["ansiblels"] = function() - require("lspconfig")['ansiblels'].setup({ - filetypes = { - "yaml", - }, - }) - end, - ["astro"] = function() - require("lspconfig")['astro'].setup({ - filetypes = { - "astro", - }, - }) - end, + ["ansiblels"] = function() + require("lspconfig")['ansiblels'].setup({ + filetypes = { + "yaml", + }, + }) + end, + ["rust-analyzer"] = function() + require("lspconfig")['rust-analyzer'].setup({ + cargo = { + buildScripts = { + enable = true, + }, + }, + filetypes = { + "rs", + }, + rustfmt = { + extraArgs = { "+nightly" }, + }, + }) + end, + ["astro"] = function() + require("lspconfig")['astro'].setup({ + filetypes = { + "astro", + }, + }) + end, - } - }) + } + }) - vim.api.nvim_create_autocmd('LspAttach', { - -- group = vim.api.nvim_create_augroup('KamuLspConfig', {}), - callback = function(ev) - local opts = { buffer = ev.buf } - local client = vim.lsp.get_client_by_id(ev.data.client_id) - if not client then return end + vim.api.nvim_create_autocmd('LspAttach', { + -- group = vim.api.nvim_create_augroup('KamuLspConfig', {}), + callback = function(ev) + local opts = { buffer = ev.buf } + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if not client then return end - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "ca", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } - end, opts) + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "gr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "ca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) - vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) - vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) - vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) - vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) - -- Format on save - if client.supports_method('textDocument/formatting') and vim.bo.filetype == "lua" then - vim.api.nvim_create_autocmd('BufWritePre', { - buffer = ev.buf, + -- Format on save + if client.supports_method('textDocument/formatting') and vim.bo.filetype == "lua" then + vim.api.nvim_create_autocmd('BufWritePre', { + buffer = ev.buf, + callback = function() + vim.lsp.buf.format({ bufnr = ev.buf, id = client.id }) + end, + }) + end + + vim.opt.updatetime = 100 + + -- Show diagnostic popup on cursor hover + local diag_float_grp = vim.api.nvim_create_augroup("DiagnosticFloat", { clear = true }) + vim.api.nvim_create_autocmd("CursorHold", { callback = function() - vim.lsp.buf.format({ bufnr = ev.buf, id = client.id }) + vim.diagnostic.open_float(nil, { focusable = false }) end, + group = diag_float_grp, }) - end - end, - }) - end + end, + }) + end + }, + -- { + -- 'mrcjkb/rustaceanvim', + -- version = '^5', -- Recommended + -- lazy = false, -- This plugin is already lazy + -- } } diff --git a/.config/nvim/lua/kamu/plugins/snacks.lua b/.config/nvim/lua/kamu/plugins/snacks.lua index 67dd535..0a99a0f 100644 --- a/.config/nvim/lua/kamu/plugins/snacks.lua +++ b/.config/nvim/lua/kamu/plugins/snacks.lua @@ -3,39 +3,17 @@ return { priority = 1000, lazy = false, keys = { - { "sh", "lua Snacks.notifier.show_history()", mode = "n", desc = "Show the notification History" } + { "sh", "lua Snacks.notifier.show_history()", mode = "n", desc = "Show the notification History" }, + { "", function() Snacks.picker.smart() end, desc = "Smart Find Files" }, }, opts = { + dashboard = { enabled = true }, bigfile = { enabled = true }, - notifier = { - enabled = true, - { - timeout = 3000, -- default timeout in ms - width = { min = 40, max = 0.4 }, - height = { min = 1, max = 0.6 }, - margin = { top = 0, right = 1, bottom = 0 }, - padding = true, -- add 1 cell of left/right padding to the notification window - sort = { "level", "added" }, -- sort by level and time - level = vim.log.levels.TRACE, - icons = { - error = " ", - warn = " ", - info = " ", - debug = " ", - trace = " ", - }, - keep = function(notif) - return vim.fn.getcmdpos() > 0 - end, - style = "compact", - top_down = true, -- place notifications from top to bottom - date_format = "%R", -- time format for notifications - more_format = " ↓ %d lines ", - refresh = 50, -- refresh at most every 50ms - } - }, + notifier = { enabled = true }, quickfile = { enabled = true }, + picker = { enabled = true }, statuscolumn = { enabled = true }, + image = { enabled = true }, words = { enabled = true }, }, init = function() diff --git a/.config/nvim/lua/kamu/plugins/treesitter.lua b/.config/nvim/lua/kamu/plugins/treesitter.lua index 9226e9a..870f593 100644 --- a/.config/nvim/lua/kamu/plugins/treesitter.lua +++ b/.config/nvim/lua/kamu/plugins/treesitter.lua @@ -20,7 +20,6 @@ return { "javascript", "dockerfile", "html", - "latex", "css", "scss", },