From 585d8eb7a10548cee28fe2b554a880bcc11e7bcd Mon Sep 17 00:00:00 2001 From: Haelnorr Date: Fri, 31 Jan 2025 17:06:59 +1100 Subject: [PATCH] Updated keybinds for which-key integration --- README.md | 4 +- lazy-lock.json | 2 +- lua/haelnorr/init.lua | 53 +++++++--- lua/haelnorr/lazy/aerial.lua | 2 +- lua/haelnorr/lazy/conform.lua | 81 +++++++------- lua/haelnorr/lazy/dadbod.lua | 13 ++- lua/haelnorr/lazy/fugitive.lua | 75 ++++++------- lua/haelnorr/lazy/harpoon.lua | 25 ++--- lua/haelnorr/lazy/init.lua | 10 +- lua/haelnorr/lazy/lsp.lua | 1 + lua/haelnorr/lazy/markdown-preview.lua | 15 +-- lua/haelnorr/lazy/refactoring.lua | 14 +-- lua/haelnorr/lazy/telescope.lua | 18 ++-- lua/haelnorr/lazy/todo-comments.lua | 2 +- lua/haelnorr/lazy/trouble.lua | 34 +++--- lua/haelnorr/lazy/undotree.lua | 10 +- lua/haelnorr/lazy/which-key.lua | 139 +++++++++++++++++++++++++ lua/haelnorr/remap.lua | 40 ++----- 18 files changed, 330 insertions(+), 208 deletions(-) diff --git a/README.md b/README.md index 87b2b12..cf25498 100644 --- a/README.md +++ b/README.md @@ -170,8 +170,8 @@ Extensible fuzzy finder for NeoVim |---------|---------------|------| | `pf` | Find files | Normal | | `Ctrl + p` | Find git files | Normal | -| `pws` | Search files for `` (word the cursor is on) | Normal | -| `pWs` | Search files for `` (WORD the cursor is on) | Normal | +| `pw` | Search files for `` (word the cursor is on) | Normal | +| `pW` | Search files for `` (WORD the cursor is on) | Normal | | `ps` | Search files with grep | Normal | | `vh` | Search builtin documentation | Normal | diff --git a/lazy-lock.json b/lazy-lock.json index e9898e8..64c452f 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -21,7 +21,7 @@ "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "nvim": { "branch": "main", "commit": "4965db2d6155c25db4e8417465fc2703fdf4c2b7" }, "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, - "nvim-lspconfig": { "branch": "master", "commit": "8c5620b04121864a1b5af134d4c2c23cee68b6ef" }, + "nvim-lspconfig": { "branch": "master", "commit": "ead2fbc4893fdd062e1dd0842679a48bfb7bac5c" }, "nvim-surround": { "branch": "main", "commit": "ae298105122c87bbe0a36b1ad20b06d417c0433e" }, "nvim-treesitter": { "branch": "master", "commit": "110bdf91e3fcbc019efbac13026ae4ad9e4ededf" }, "nvim-web-devicons": { "branch": "master", "commit": "1c9136332840edee0c593f2f4f89598c8ed97f5f" }, diff --git a/lua/haelnorr/init.lua b/lua/haelnorr/init.lua index 5ac51c9..73b94f1 100644 --- a/lua/haelnorr/init.lua +++ b/lua/haelnorr/init.lua @@ -3,29 +3,48 @@ require("haelnorr.remap") require("haelnorr.lazy_init") local augroup = vim.api.nvim_create_augroup -local HaelnorrGroup = augroup('Haelnorr', {}) +local HaelnorrGroup = augroup("Haelnorr", {}) local autocmd = vim.api.nvim_create_autocmd function R(name) - require("plenary.reload").reload_module(name) + require("plenary.reload").reload_module(name) end -autocmd('LspAttach', { - group = HaelnorrGroup, - callback = function(e) - local opts = { buffer = e.buf } - 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", "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", "vca", function() vim.lsp.buf.code_action() 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", "[d", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) - end +autocmd("LspAttach", { + group = HaelnorrGroup, + callback = function(e) + vim.keymap.set("n", "gd", function() + vim.lsp.buf.definition() + end, { buffer = e.buf, desc = "Goto definition" }) + vim.keymap.set("n", "K", function() + vim.lsp.buf.hover() + end, { buffer = e.buf, desc = "Display hover" }) + vim.keymap.set("n", "vs", function() + vim.lsp.buf.workspace_symbol() + end, { buffer = e.buf, desc = "Find symbol in workspace" }) + vim.keymap.set("n", "vf", function() + vim.diagnostic.open_float() + end, { buffer = e.buf, desc = "Show diagnostics" }) + vim.keymap.set("n", "va", function() + vim.lsp.buf.code_action() + end, { buffer = e.buf, desc = "Code action" }) + vim.keymap.set("n", "vs", function() + vim.lsp.buf.references() + end, { buffer = e.buf, desc = "List references to symbol" }) + vim.keymap.set("n", "vr", function() + vim.lsp.buf.rename() + end, { buffer = e.buf, desc = "Rename symbol" }) + vim.keymap.set("i", "", function() + vim.lsp.buf.signature_help() + end, { buffer = e.buf, desc = "Display signature" }) + vim.keymap.set("n", "[d", function() + vim.diagnostic.goto_next() + end, { buffer = e.buf, desc = "Next diagnostic" }) + vim.keymap.set("n", "]d", function() + vim.diagnostic.goto_prev() + end, { buffer = e.buf, desc = "Prev diagnostic" }) + end, }) vim.g.netrw_browse_split = 0 diff --git a/lua/haelnorr/lazy/aerial.lua b/lua/haelnorr/lazy/aerial.lua index cfd9248..787322b 100644 --- a/lua/haelnorr/lazy/aerial.lua +++ b/lua/haelnorr/lazy/aerial.lua @@ -27,6 +27,6 @@ return { "Method", }, }) - vim.keymap.set("n", "pa", "AerialToggle!") + vim.keymap.set("n", "oa", "AerialToggle!", { desc = "Toggle Aerial" }) end, } diff --git a/lua/haelnorr/lazy/conform.lua b/lua/haelnorr/lazy/conform.lua index 558a594..7e8daba 100644 --- a/lua/haelnorr/lazy/conform.lua +++ b/lua/haelnorr/lazy/conform.lua @@ -1,48 +1,37 @@ return { - "stevearc/conform.nvim", - event = { "BufWritePre" }, - cmd = { "ConformInfo" }, - keys = { - { - -- Customize or remove this keymap to your liking - "f", - function() - require("conform").format({ async = true }) - end, - mode = "", - desc = "Format buffer", - }, - }, - -- This will provide type hinting with LuaLS - ---@module "conform" - ---@type conform.setupOpts - opts = { - -- Define your formatters - formatters_by_ft = { - lua = { "stylua" }, - python = { "isort", "black" }, - javascript = { "prettierd", "prettier", stop_after_first = true }, - typescript = { "prettierd", "prettier", stop_after_first = true }, - typescriptreact = { "prettierd", "prettier", stop_after_first = true }, - json = { "prettierd", "prettier", stop_after_first = true }, - html = { "prettierd", "prettier", stop_after_first = true }, - css = { "prettierd", "prettier", stop_after_first = true }, - }, - -- Set default options - default_format_opts = { - lsp_format = "fallback", - }, - -- Set up format-on-save - format_on_save = { timeout_ms = 500 }, - -- Customize formatters - formatters = { - shfmt = { - prepend_args = { "-i", "2" }, - }, - }, - }, - init = function() - -- If you want the formatexpr, here is the place to set it - vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" - end, + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + -- This will provide type hinting with LuaLS + ---@module "conform" + ---@type conform.setupOpts + opts = { + -- Define your formatters + formatters_by_ft = { + lua = { "stylua" }, + python = { "isort", "black" }, + javascript = { "prettierd", "prettier", stop_after_first = true }, + typescript = { "prettierd", "prettier", stop_after_first = true }, + typescriptreact = { "prettierd", "prettier", stop_after_first = true }, + json = { "prettierd", "prettier", stop_after_first = true }, + html = { "prettierd", "prettier", stop_after_first = true }, + css = { "prettierd", "prettier", stop_after_first = true }, + }, + -- Set default options + default_format_opts = { + lsp_format = "fallback", + }, + -- Set up format-on-save + format_on_save = { timeout_ms = 500 }, + -- Customize formatters + formatters = { + shfmt = { + prepend_args = { "-i", "2" }, + }, + }, + }, + init = function() + -- If you want the formatexpr, here is the place to set it + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + end, } diff --git a/lua/haelnorr/lazy/dadbod.lua b/lua/haelnorr/lazy/dadbod.lua index 2e67676..afd81e3 100644 --- a/lua/haelnorr/lazy/dadbod.lua +++ b/lua/haelnorr/lazy/dadbod.lua @@ -1,8 +1,15 @@ return { "kristijanhusak/vim-dadbod-ui", dependencies = { - { "tpope/vim-dadbod", lazy = true }, - { "kristijanhusak/vim-dadbod-completion", ft = { "sql", "mysql", "plsql" }, lazy = true }, -- Optional + { + "tpope/vim-dadbod", + lazy = true, + }, + { + "kristijanhusak/vim-dadbod-completion", + ft = { "sql", "mysql", "plsql" }, + lazy = true, + }, }, cmd = { "DBUI", @@ -11,7 +18,7 @@ return { "DBUIFindBuffer", }, init = function() - -- Your DBUI configuration vim.g.db_ui_use_nerd_fonts = 1 + vim.keymap.set("n", "od", "DBUIToggle", { desc = "Toggle Dadbod UI" }) end, } diff --git a/lua/haelnorr/lazy/fugitive.lua b/lua/haelnorr/lazy/fugitive.lua index 1fdbb0e..6136ee1 100644 --- a/lua/haelnorr/lazy/fugitive.lua +++ b/lua/haelnorr/lazy/fugitive.lua @@ -1,44 +1,47 @@ return { - "tpope/vim-fugitive", - config = function() - vim.keymap.set("n", "gs", vim.cmd.Git) + "tpope/vim-fugitive", + config = function() + vim.keymap.set("n", "g", vim.cmd.Git, { desc = "Open Git fugitive" }) - local Haelnorr_Fugitive = vim.api.nvim_create_augroup("Haelnorr_Fugitive", {}) + local Haelnorr_Fugitive = vim.api.nvim_create_augroup("Haelnorr_Fugitive", {}) - local autocmd = vim.api.nvim_create_autocmd - autocmd("BufWinEnter", { - group = Haelnorr_Fugitive, - pattern = "*", - callback = function() - if vim.bo.ft ~= "fugitive" then - return - end + local autocmd = vim.api.nvim_create_autocmd + autocmd("BufWinEnter", { + group = Haelnorr_Fugitive, + pattern = "*", + callback = function() + if vim.bo.ft ~= "fugitive" then + return + end - local bufnr = vim.api.nvim_get_current_buf() - local opts = {buffer = bufnr, remap = false} - vim.keymap.set("n", "s", function() - vim.cmd.Git('add -A') - end, opts) - vim.keymap.set("n", "c", function() - vim.cmd.Git('commit') - end, opts) - vim.keymap.set("n", "p", function() - vim.cmd.Git('push') - end, opts) + local bufnr = vim.api.nvim_get_current_buf() + vim.keymap.set("n", "s", function() + vim.cmd.Git("add -A") + end, { buffer = bufnr, remap = false, desc = "Stage all files" }) + vim.keymap.set("n", "c", function() + vim.cmd.Git("commit") + end, { buffer = bufnr, remap = false, desc = "Commit" }) + vim.keymap.set("n", "p", function() + vim.cmd.Git("push") + end, { buffer = bufnr, remap = false, desc = "Push" }) - -- rebase always - vim.keymap.set("n", "P", function() - vim.cmd.Git({'pull', '--rebase'}) - end, opts) + -- rebase always + vim.keymap.set("n", "P", function() + vim.cmd.Git({ "pull", "--rebase" }) + end, { buffer = bufnr, remap = false, desc = "Pull with rebase" }) - -- NOTE: It allows me to easily set the branch i am pushing and any tracking - -- needed if i did not set the branch up correctly - vim.keymap.set("n", "t", ":Git push -u origin ", opts); - end, - }) + -- NOTE: It allows me to easily set the branch i am pushing and any tracking + -- needed if i did not set the branch up correctly + vim.keymap.set( + "n", + "t", + ":Git push -u origin ", + { buffer = bufnr, remap = false, desc = "Push and set origin" } + ) + end, + }) - - vim.keymap.set("n", "gu", "diffget //2") - vim.keymap.set("n", "gh", "diffget //3") - end + vim.keymap.set("n", "gu", "diffget //2") + vim.keymap.set("n", "gh", "diffget //3") + end, } diff --git a/lua/haelnorr/lazy/harpoon.lua b/lua/haelnorr/lazy/harpoon.lua index f63bbe9..66148c2 100644 --- a/lua/haelnorr/lazy/harpoon.lua +++ b/lua/haelnorr/lazy/harpoon.lua @@ -1,20 +1,9 @@ return { - "ThePrimeagen/harpoon", - branch = "harpoon2", - dependencies = { "nvim-lua/plenary.nvim" }, - config = function() - local harpoon = require("harpoon") - - harpoon:setup() - vim.keymap.set("n", "a", function() harpoon:list():add() end) - vim.keymap.set("n", "", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) - vim.keymap.set("n", "", function() harpoon:list():select(1) end) - vim.keymap.set("n", "", function() harpoon:list():select(2) end) - vim.keymap.set("n", "", function() harpoon:list():select(3) end) - vim.keymap.set("n", "", function() harpoon:list():select(4) end) - vim.keymap.set("n", "", function() harpoon:list():replace_at(1) end) - vim.keymap.set("n", "", function() harpoon:list():replace_at(2) end) - vim.keymap.set("n", "", function() harpoon:list():replace_at(3) end) - vim.keymap.set("n", "", function() harpoon:list():replace_at(4) end) - end + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + local harpoon = require("harpoon") + harpoon:setup() + end, } diff --git a/lua/haelnorr/lazy/init.lua b/lua/haelnorr/lazy/init.lua index a490730..32bbcc8 100644 --- a/lua/haelnorr/lazy/init.lua +++ b/lua/haelnorr/lazy/init.lua @@ -1,9 +1,9 @@ return { - { - "nvim-lua/plenary.nvim", - name = "plenary" - }, + { + "nvim-lua/plenary.nvim", + name = "plenary", + }, - "eandrju/cellular-automaton.nvim", + "eandrju/cellular-automaton.nvim", } diff --git a/lua/haelnorr/lazy/lsp.lua b/lua/haelnorr/lazy/lsp.lua index a621433..f1e1581 100644 --- a/lua/haelnorr/lazy/lsp.lua +++ b/lua/haelnorr/lazy/lsp.lua @@ -20,6 +20,7 @@ return { end vim.tbl_map(function(type) require("luasnip.loaders.from_" .. type).lazy_load() + vim.keymap.set("n", "ts", "Telescope luasnip", { desc = "Search Snippets" }) end, { "vscode", "snipmate", "lua" }) end, }, diff --git a/lua/haelnorr/lazy/markdown-preview.lua b/lua/haelnorr/lazy/markdown-preview.lua index bb96fbc..611ac90 100644 --- a/lua/haelnorr/lazy/markdown-preview.lua +++ b/lua/haelnorr/lazy/markdown-preview.lua @@ -1,9 +1,10 @@ return { - "iamcco/markdown-preview.nvim", - cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, - build = "cd app && yarn install", - init = function() - vim.g.mkdp_filetypes = { "markdown" } - end, - ft = { "markdown" }, + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + build = "cd app && yarn install", + init = function() + vim.g.mkdp_filetypes = { "markdown" } + vim.keymap.set("n", "om", "MarkdownPreviewToggle", { desc = "Toggle MarkdownPreview" }) + end, + ft = { "markdown" }, } diff --git a/lua/haelnorr/lazy/refactoring.lua b/lua/haelnorr/lazy/refactoring.lua index 314498d..79143bc 100644 --- a/lua/haelnorr/lazy/refactoring.lua +++ b/lua/haelnorr/lazy/refactoring.lua @@ -7,16 +7,16 @@ return { lazy = false, config = function() require("refactoring").setup() - vim.keymap.set("x", "re", ":Refactor extract ") - vim.keymap.set("x", "rf", ":Refactor extract_to_file ") + vim.keymap.set("x", "re", ":Refactor extract ", { desc = "Extract selection" }) + vim.keymap.set("x", "rf", ":Refactor extract_to_file ", { desc = "Extract selection to new file" }) - vim.keymap.set("x", "rv", ":Refactor extract_var ") + vim.keymap.set("x", "rv", ":Refactor extract_var ", { desc = "Extract var" }) - vim.keymap.set({ "n", "x" }, "ri", ":Refactor inline_var") + vim.keymap.set({ "n", "x" }, "ri", ":Refactor inline_var", { desc = "Inline var" }) - vim.keymap.set("n", "rI", ":Refactor inline_func") + vim.keymap.set("n", "rI", ":Refactor inline_func", { desc = "Inline function" }) - vim.keymap.set("n", "rb", ":Refactor extract_block") - vim.keymap.set("n", "rbf", ":Refactor extract_block_to_file") + vim.keymap.set("n", "rb", ":Refactor extract_block", { desc = "Extract block" }) + vim.keymap.set("n", "rbf", ":Refactor extract_block_to_file", { desc = "Extract block to new file" }) end, } diff --git a/lua/haelnorr/lazy/telescope.lua b/lua/haelnorr/lazy/telescope.lua index bf7a120..054afe5 100644 --- a/lua/haelnorr/lazy/telescope.lua +++ b/lua/haelnorr/lazy/telescope.lua @@ -13,19 +13,19 @@ return { }) local builtin = require("telescope.builtin") - vim.keymap.set("n", "pf", builtin.find_files, {}) - vim.keymap.set("n", "", builtin.git_files, {}) - vim.keymap.set("n", "pws", function() + vim.keymap.set("n", "tf", builtin.find_files, { desc = "Find files" }) + vim.keymap.set("n", "", builtin.git_files, { desc = "Find git files" }) + vim.keymap.set("n", "tw", function() local word = vim.fn.expand("") builtin.grep_string({ search = word }) - end) - vim.keymap.set("n", "pWs", function() + end, { desc = "Search files with " }) + vim.keymap.set("n", "tW", function() local word = vim.fn.expand("") builtin.grep_string({ search = word }) - end) - vim.keymap.set("n", "ps", function() + end, { desc = "Search files with " }) + vim.keymap.set("n", "tg", function() builtin.grep_string({ search = vim.fn.input("Grep > ") }) - end) - vim.keymap.set("n", "vh", builtin.help_tags, {}) + end, { desc = "Search files with grep" }) + vim.keymap.set("n", "th", builtin.help_tags, { desc = "Search help tags" }) end, } diff --git a/lua/haelnorr/lazy/todo-comments.lua b/lua/haelnorr/lazy/todo-comments.lua index 36c8766..46965db 100644 --- a/lua/haelnorr/lazy/todo-comments.lua +++ b/lua/haelnorr/lazy/todo-comments.lua @@ -7,6 +7,6 @@ return { opts = {}, config = function() require("todo-comments").setup() - vim.keymap.set("n", "ts", ":TodoTelescope cwd=") + vim.keymap.set("n", "tt", ":TodoTelescope cwd=", { desc = "Search Todos" }) end, } diff --git a/lua/haelnorr/lazy/trouble.lua b/lua/haelnorr/lazy/trouble.lua index e861b1b..eb81488 100644 --- a/lua/haelnorr/lazy/trouble.lua +++ b/lua/haelnorr/lazy/trouble.lua @@ -1,19 +1,19 @@ return { - { - "folke/trouble.nvim", - opts = {}, - cmd = "Trouble", - keys = { - { - "tt", - "Trouble diagnostics toggle", - desc = "Diagnostics (Trouble)", - }, - { - "tq", - "Trouble qflist toggle", - desc = "Quickfix List (Trouble)", - }, - }, - }, + { + "folke/trouble.nvim", + opts = {}, + cmd = "Trouble", + keys = { + { + "ot", + "Trouble diagnostics toggle", + desc = "Toggle Diagnostics (Trouble)", + }, + { + "oq", + "Trouble qflist toggle", + desc = "Toggle Quickfix List (Trouble)", + }, + }, + }, } diff --git a/lua/haelnorr/lazy/undotree.lua b/lua/haelnorr/lazy/undotree.lua index f76ae05..5beff39 100644 --- a/lua/haelnorr/lazy/undotree.lua +++ b/lua/haelnorr/lazy/undotree.lua @@ -1,9 +1,7 @@ - return { - "mbbill/undotree", + "mbbill/undotree", - config = function() - vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) - end + config = function() + vim.keymap.set("n", "ou", vim.cmd.UndotreeToggle, { desc = "Toggle Undotree" }) + end, } - diff --git a/lua/haelnorr/lazy/which-key.lua b/lua/haelnorr/lazy/which-key.lua index 1b2e8ce..5c25b1f 100644 --- a/lua/haelnorr/lazy/which-key.lua +++ b/lua/haelnorr/lazy/which-key.lua @@ -11,4 +11,143 @@ return { desc = "Buffer Local Keymaps (which-key)", }, }, + config = function() + local harpoon = require("harpoon") + require("which-key").add({ + { "t", group = "Telescope" }, + { "o", group = "Open plugin", icon = { icon = "", color = "yellow" } }, + { "r", group = "Refactoring", mode = { "n", "x" } }, + { "v", group = "LSP Actions", icon = { icon = "󰅡" } }, + + -- Harpoon + -- Quick jumps and show list + { + "", + function() + harpoon.ui:toggle_quick_menu(harpoon:list()) + end, + }, + { + "", + function() + harpoon:list():select(1) + end, + }, + { + "", + function() + harpoon:list():select(2) + end, + }, + { + "", + function() + harpoon:list():select(3) + end, + }, + { + "", + function() + harpoon:list():select(4) + end, + }, + + -- Add files + { + "a", + function() + harpoon:list():add() + end, + desc = "Harpoon current file", + mode = "n", + icon = { icon = "󱡅", color = "blue" }, + }, + { + "", + function() + harpoon:list():replace_at(1) + end, + desc = "Harpoon at file 1", + mode = "n", + icon = { icon = "󱡅", color = "blue" }, + }, + { + "", + function() + harpoon:list():replace_at(2) + end, + desc = "Harpoon at file 2", + mode = "n", + icon = { icon = "󱡅", color = "blue" }, + }, + { + "", + function() + harpoon:list():replace_at(3) + end, + desc = "Harpoon at file 3", + mode = "n", + icon = { icon = "󱡅", color = "blue" }, + }, + { + "", + function() + harpoon:list():replace_at(4) + end, + desc = "Harpoon at file 4", + mode = "n", + icon = { icon = "󱡅", color = "blue" }, + }, + + -- Custom binds + + { + "y", + [["+y]], + desc = "Yank to system clipboard", + mode = { "n", "v" }, + icon = { icon = "", color = "yellow" }, + }, + { + "Y", + [["+Y]], + desc = "Yank line to system clipboard", + mode = "n", + icon = { icon = "", color = "yellow" }, + }, + + { + "p", + [["_dP]], + desc = "Paste over selection, preserving buffer", + mode = "x", + icon = { icon = "", color = "yellow" }, + }, + { + "d", + [["_d]], + desc = "Delete, preserving buffer", + mode = { "n", "v" }, + icon = { icon = "", color = "red" }, + }, + { + "x", + "!chmod +x %", + silent = true, + desc = "Make file executable", + icon = { icon = "", color = "red" }, + }, + + -- Conform + { + "f", + function() + require("conform").format({ async = true }) + end, + mode = "n", + desc = "Format file", + icon = { icon = "󰉼", color = "yellow" }, + }, + }) + end, } diff --git a/lua/haelnorr/remap.lua b/lua/haelnorr/remap.lua index 9d8f9b6..1b92e57 100644 --- a/lua/haelnorr/remap.lua +++ b/lua/haelnorr/remap.lua @@ -1,7 +1,4 @@ vim.g.mapleader = " " --- directory viewer --- has been replaced with Oil.nvim, keybind "-" --- vim.keymap.set("n", "pv", vim.cmd.Ex) -- move highlighted lines up and down vim.keymap.set("v", "J", ":m '>+1gv=gv") @@ -13,38 +10,17 @@ vim.keymap.set("n", "", "zz") vim.keymap.set("n", "n", "nzzzv") vim.keymap.set("n", "N", "Nzzzv") --- pastes without replacing buffer -vim.keymap.set("x", "p", [["_dP]]) - --- yanks to system clipboard -vim.keymap.set({ "n", "v" }, "y", [["+y]]) -vim.keymap.set("n", "Y", [["+Y]]) - --- deletes without replacing buffer -vim.keymap.set({ "n", "v" }, "d", [["_d]]) - --- formats file using LSP --- vim.keymap.set("n", "f", vim.lsp.buf.format) -vim.keymap.set("", "f", function() - require("conform").format({ async = true }, function(err) - if not err then - local mode = vim.api.nvim_get_mode().mode - if vim.startswith(string.lower(mode), "v") then - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true) - end - end - end) -end, { desc = "Format code" }) - vim.keymap.set("n", "", "cnextzz") vim.keymap.set("n", "", "cprevzz") -vim.keymap.set("n", "k", "lnextzz") -vim.keymap.set("n", "j", "lprevzz") +vim.keymap.set("n", "k", "lnextzz", { desc = "Quickfix next" }) +vim.keymap.set("n", "j", "lprevzz", { desc = "Quickfix prev" }) -vim.keymap.set("n", "s", [[:%s/\<\>//gI]]) -vim.keymap.set("n", "x", "!chmod +x %", { silent = true }) - -vim.keymap.set("n", "o", "ok") +vim.keymap.set( + "n", + "s", + [[:%s/\<\>//gI]], + { desc = "Find and replace word" } +) vim.keymap.set("n", "", function() if vim.inspect(vim.opt.colorcolumn:get()) == "{}" then