diff --git a/home/common/nvim/init.lua b/home/common/nvim/init.lua index b9372e9..682ef71 100644 --- a/home/common/nvim/init.lua +++ b/home/common/nvim/init.lua @@ -1,4 +1,4 @@ -vim.g.mapleader = "" +vim.g.mapleader = ' ' vim.g.maplocalleader = "," -- UI @@ -14,13 +14,14 @@ vim.opt.termguicolors = true -- Ruler function GetIndicators() local bufnr = vim.api.nvim_get_current_buf() - local counts = vim.diagnostic.count(bufnr) - local errors = counts[vim.diagnostic.severity.ERROR] or 0 - local warnings = counts[vim.diagnostic.severity.WARN] or 0 - local warn_string = warnings > 0 and "%#DiagnosticWarn# " .. warnings .. " " or " " - local error_string = errors > 0 and "%#DiagnosticError# " .. errors .. " " or " " - return warn_string .. error_string + local counts = vim.diagnostic.count(bufnr) + local errors = counts[vim.diagnostic.severity.ERROR] or 0 + local warnings = counts[vim.diagnostic.severity.WARN] or 0 + local warn_string = warnings > 0 and "%#DiagnosticWarn# " .. warnings .. " " or " " + local error_string = errors > 0 and "%#DiagnosticError# " .. errors .. " " or " " + return warn_string .. error_string end + vim.opt.rulerformat = "%40(%=%{%v:lua.GetIndicators()%}%#Label#│ %t %)" -- Search @@ -95,8 +96,72 @@ vim.keymap.set({ "i", "s" }, "", function() end end, { expr = true }) -vim.keymap.set({ "n" }, "", "gcc", { remap = true }) -vim.keymap.set({ "v" }, "", "gc", { remap = true }) -vim.keymap.set({ "n" }, "", "gcc", { remap = true }) -vim.keymap.set({ "v" }, "", "gc", { remap = true }) + +-- Keymap +local opts = function(label) + return { noremap = true, silent = true, desc = label } +end + +-- Comments +vim.keymap.set("n", "", "gcc", { remap = true }) +vim.keymap.set("v", "", "gc", { remap = true }) +vim.keymap.set("n", "", "gcc", { remap = true }) +vim.keymap.set("v", "", "gc", { remap = true }) + +vim.keymap.set({ "n", "v" }, "a", vim.lsp.buf.code_action, { remap = true, desc = "Code action" }) +vim.keymap.set("n", "af", function() + vim.lsp.buf.format({ async = true }) +end, opts("Format Buffer")) +vim.keymap.set('n', 'b', "Pick buffers", opts("Open buffer picker")) +vim.keymap.set('n', '/', "Pick grep_live_root", opts("Search workspace files")) +vim.keymap.set('n', 'd', "Pick diagnostic", opts("Open diagnostics picker")) +vim.keymap.set("n", "D", vim.diagnostic.setloclist, { desc = "Diagnostics to location list" }) +vim.keymap.set("n", "r", vim.lsp.buf.rename, opts("Rename Symbol")) +vim.keymap.set('n', 'F', "Pick files", opts("Open file picker CWD")) +vim.keymap.set('n', 'f', "Pick files_root", opts("Open file picker")) +vim.keymap.set('n', 'g', "Pick oldfiles", opts("Open file picker history")) +vim.keymap.set("n", 'k', vim.lsp.buf.hover, opts("Show docs for item under cursor")) +vim.keymap.set('n', 'q', require('mini.bufremove').delete, opts("Delete buffer")) +vim.keymap.set('n', 's', "Pick lsp scope='document_symbol'", opts("Open symbol picker")) +vim.keymap.set('n', 'S', "Pick lsp scope='workspace_symbol'", opts("Open workspace symbol picker")) +vim.keymap.set('n', '', "Pick buffers include_current=false", opts("Buffers")) vim.keymap.set("n", "zz", "zt", { remap = true }) +vim.keymap.set({ "n", "v" }, "y", '"+y', opts("Yank to clipboard")) +vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) +vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Declaration")) +vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Definition")) +vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Implementation")) +vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Buffer References")) +vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, opts("Type Definition")) +vim.keymap.set({"n", "i"}, "", vim.lsp.buf.signature_help, opts("Signature Help")) +vim.keymap.set({ "n", "v" }, "aa", vim.lsp.buf.code_action, opts("Code Action")) +vim.keymap.set("n", "ws", "s", opts("Horizontal split")) +vim.keymap.set("n", "wv", "v", opts("Vertical split")) + +-- Completion +vim.keymap.set('i', '', [[pumvisible() ? "\" : "\"]], { expr = true }) +vim.keymap.set('i', '', [[pumvisible() ? "\" : "\"]], { expr = true }) + +local keycode = vim.keycode or function(x) + return vim.api.nvim_replace_termcodes(x, true, true, true) +end +local keys = { + ['cr'] = keycode(''), + ['ctrl-y'] = keycode(''), + ['ctrl-y_cr'] = keycode(''), +} + +_G.cr_action = function() + if vim.fn.pumvisible() ~= 0 then + -- If popup is visible, confirm selected item or add new line otherwise + local item_selected = vim.fn.complete_info()['selected'] ~= -1 + return item_selected and keys['ctrl-y'] or keys['ctrl-y_cr'] + else + -- If popup is not visible, use plain ``. You might want to customize + -- according to other plugins. For example, to use 'mini.pairs', replace + -- next line with `return require('mini.pairs').cr()` + return keys['cr'] + end +end + +vim.keymap.set('i', '', 'v:lua._G.cr_action()', { expr = true }) diff --git a/home/common/nvim/lsp.lua b/home/common/nvim/lsp.lua index 096b556..94f92fe 100644 --- a/home/common/nvim/lsp.lua +++ b/home/common/nvim/lsp.lua @@ -1,5 +1,3 @@ -vim.keymap.set("n", "d", vim.diagnostic.setloclist, { desc = "Add buffer diagnostics to the location list." }) - vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev) @@ -16,28 +14,6 @@ vim.api.nvim_create_autocmd("LspAttach", { if client.server_capabilities.codeLensProvider then vim.lsp.codelens.refresh({ bufnr = bufnr }) end - - vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) - vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, {}) - - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Declaration")) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Definition")) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Implementation")) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts("Signature Help")) - vim.keymap.set("i", "", vim.lsp.buf.signature_help, opts("Signature Help")) - vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts("Add Workspace Folder")) - vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts("Remove Workspace Folder")) - vim.keymap.set("n", "wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, opts("List Workspace Folders")) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts("Type Definition")) - vim.keymap.set("n", "r", vim.lsp.buf.rename, opts("Rename Symbol")) - vim.keymap.set({ "n", "v" }, "a", vim.lsp.buf.code_action, opts("Code Action")) - vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Buffer References")) - vim.keymap.set("n", "cf", function() - vim.lsp.buf.format({ async = true }) - end, opts("Format Buffer")) end, }) diff --git a/home/common/nvim/mini.lua b/home/common/nvim/mini.lua index 6424343..c37cb52 100644 --- a/home/common/nvim/mini.lua +++ b/home/common/nvim/mini.lua @@ -1,9 +1,7 @@ -local opts = function(label) - return { noremap = true, silent = true, desc = label } -end require('mini.ai').setup() require('mini.align').setup() require('mini.bracketed').setup() +require('mini.bufremove').setup() require('mini.comment').setup() require('mini.diff').setup() require('mini.extra').setup() @@ -13,50 +11,16 @@ require('mini.surround').setup() require('mini.splitjoin').setup() require('mini.trailspace').setup() -local bufremove = require('mini.bufremove') -bufremove.setup() -vim.keymap.set('n', 'bd', bufremove.delete, opts("Delete")) - require('mini.cursorword').setup({ delay = 800 }) require('mini.completion').setup({ - window = { + window = { info = { height = 25, width = 80, border = 'rounded' }, signature = { height = 25, width = 80, border = 'rounded' }, }, }) -local imap_expr = function(lhs, rhs) - vim.keymap.set('i', lhs, rhs, { expr = true }) -end -imap_expr('', [[pumvisible() ? "\" : "\"]]) -imap_expr('', [[pumvisible() ? "\" : "\"]]) - - local keycode = vim.keycode or function(x) - return vim.api.nvim_replace_termcodes(x, true, true, true) - end - local keys = { - ['cr'] = keycode(''), - ['ctrl-y'] = keycode(''), - ['ctrl-y_cr'] = keycode(''), - } - - _G.cr_action = function() - if vim.fn.pumvisible() ~= 0 then - -- If popup is visible, confirm selected item or add new line otherwise - local item_selected = vim.fn.complete_info()['selected'] ~= -1 - return item_selected and keys['ctrl-y'] or keys['ctrl-y_cr'] - else - -- If popup is not visible, use plain ``. You might want to customize - -- according to other plugins. For example, to use 'mini.pairs', replace - -- next line with `return require('mini.pairs').cr()` - return keys['cr'] - end - end - - vim.keymap.set('i', '', 'v:lua._G.cr_action()', { expr = true }) - local hipatterns = require('mini.hipatterns') @@ -84,9 +48,33 @@ require('mini.jump2d').setup({ mappings = { start_jumping = 'gw' } }) +local picker_win_config = function() + height = vim.o.lines - 8 + width = 80 + return { + border = 'rounded', + anchor = 'NW', + height = height, + width = width, + row = 2, + col = math.floor((vim.o.columns - width) / 2), + } +end + require('mini.pick').setup({ - mappings = { move_down = '' }, - options = { use_cache = true } + mappings = { + move_down = '', + toggle_info = '', + toggle_preview = '', + }, + options = { use_cache = true }, + window = { + config = picker_win_config, + -- config = { + -- border = 'rounded', + -- width = 'auto', + -- }, + }, }) MiniPick.registry.files_root = function(local_opts) local root_patterns = { ".jj", ".git" } @@ -101,13 +89,6 @@ MiniPick.registry.grep_live_root = function(local_opts) local_opts.cwd = root_dir return MiniPick.builtin.grep_live(local_opts, { source = { cwd = root_dir } }) end -vim.keymap.set('n', '/', "Pick grep_live_root", opts("Live Grep")) -vim.keymap.set('n', 'fF', "Pick files", opts("FindCWD")) -vim.keymap.set('n', 'ff', "Pick files_root", opts("Find")) -vim.keymap.set('n', 'fr', "Pick oldfiles", opts("Recent")) -vim.keymap.set('n', 'bb', "Pick buffers", opts("Switch")) -vim.keymap.set('n', 'd', "Pick diagnostics", opts("Diagnostics")) -vim.keymap.set('n', '', "Pick buffers include_current=false", opts("Buffers")) local miniclue = require('mini.clue') @@ -157,7 +138,11 @@ miniclue.setup({ -- cute prompts about bindings miniclue.gen_clues.z(), }, window = { - delay = 15, + delay = 0, + config = { + border = 'rounded', + width = 'auto', + }, } }) @@ -175,7 +160,7 @@ require('mini.notify').setup({ require('mini.starter').setup({ header = - [[ ______ _ + [[ ______ _ (_____ \ _ (_) _____) )___| |_ ____ ____ _ ____ | ____/ _ | _)/ _ |/ _ | |/ _ |