From b5be5a3659f5932c3b1f854560e3ba03cc087640 Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Tue, 1 Apr 2025 11:02:14 +0200 Subject: [PATCH] feat: use virtual_text instead of virtual_lines and add keymap to toggle this --- lua/weeheavy/prefs.lua | 11 +++-- lua/weeheavy/remap.lua | 94 +++++++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/lua/weeheavy/prefs.lua b/lua/weeheavy/prefs.lua index f794ec8..f1b52e7 100644 --- a/lua/weeheavy/prefs.lua +++ b/lua/weeheavy/prefs.lua @@ -109,10 +109,9 @@ vim.diagnostic.config({ [vim.diagnostic.severity.INFO] = "", }, }, - -- virtual_text = { current_line = true }, - -- virtual_lines = true, - -- virtual_text = true, - virtual_lines = { - current_line = true, - }, + virtual_text = true, + virtual_lines = false, + -- virtual_lines = { + -- current_line = true, + -- }, }) diff --git a/lua/weeheavy/remap.lua b/lua/weeheavy/remap.lua index fd07fd2..cc094d1 100644 --- a/lua/weeheavy/remap.lua +++ b/lua/weeheavy/remap.lua @@ -13,10 +13,10 @@ vim.keymap.set("n", "fo", ":Telescope oldfiles", { noremap = true, d -- Find files vim.keymap.set( - "n", - "ff", - ":Telescope find_files hidden=true no_ignore=false", - { noremap = true, desc = "File search" } + "n", + "ff", + ":Telescope find_files hidden=true no_ignore=false", + { noremap = true, desc = "File search" } ) -- Live find string (using ripgrep) @@ -24,10 +24,10 @@ vim.keymap.set("n", "fg", ":Telescope live_grep", { noremap = true, -- Find string under cursor (using ripgrep) vim.keymap.set( - "n", - "fs", - ":Telescope grep_string", - { noremap = true, desc = "Search text under cursor in cwd/grep search string" } + "n", + "fs", + ":Telescope grep_string", + { noremap = true, desc = "Search text under cursor in cwd/grep search string" } ) -- Find string under cursor --vim.keymap.set( @@ -42,27 +42,27 @@ vim.keymap.set("n", "", ":Telescope buffers", { noremap = tr vim.keymap.set("n", "ft", ":TodoTelescope", { noremap = true, desc = "Find TODOs" }) --vim.keymap.set("n", "gs", ":Telescope git_status", { noremap = true, desc = "Git status" }) vim.keymap.set( - "n", - "gla", - ":Telescope git_commits", - { noremap = true, desc = "Git log (across all files)" } + "n", + "gla", + ":Telescope git_commits", + { noremap = true, desc = "Git log (across all files)" } ) vim.keymap.set("n", "glf", ":Telescope git_bcommits", { noremap = true, desc = "Git log (this file)" }) --vim.keymap.set("n", "gdp", ":Gitsigns diffthis", { noremap = true, desc = "Git diff previous (this file)" }) --vim.keymap.set("n", "gd", ":Gitsigns diffthis", { noremap = true, desc = "Git diff previous (this file)" }) vim.keymap.set("n", "gd", function() - if next(require("diffview.lib").views) == nil then - vim.cmd("DiffviewOpen") - else - vim.cmd("DiffviewClose") - end - --end, { noremap = true, desc = "Diff this shit" }) + if next(require("diffview.lib").views) == nil then + vim.cmd("DiffviewOpen") + else + vim.cmd("DiffviewClose") + end + --end, { noremap = true, desc = "Diff this shit" }) end, { noremap = true, desc = "Toggle diff/stage UI " }) vim.keymap.set( - "n", - "gb", - ":Gitsigns toggle_current_line_blame", - { noremap = true, desc = "Toggle git blame" } + "n", + "gb", + ":Gitsigns toggle_current_line_blame", + { noremap = true, desc = "Toggle git blame" } ) -- Remapping of existing Vim key binds @@ -77,26 +77,26 @@ vim.keymap.set("n", "b", "B") -- skip punctuation when moving to end of previous vim.keymap.set("v", "J", ":m '>+1gv=gv") -- move whole lines/blocks down in visual mode vim.keymap.set("v", "K", ":m '<-2gv=gv") -- move whole lines/blocks up in visual mode -vim.keymap.set("n", "", "zz") -- eye-friendly down scrolling -vim.keymap.set("n", "", "zz") -- eye-friendly up scrolling +vim.keymap.set("n", "", "zz") -- eye-friendly down scrolling +vim.keymap.set("n", "", "zz") -- eye-friendly up scrolling -vim.keymap.set("n", "J", "mzJ`z") -- when merging lines, keep cursor at current position +vim.keymap.set("n", "J", "mzJ`z") -- when merging lines, keep cursor at current position vim.keymap.set( - "n", - "s", - [[:%s/\<\>//gI]], - { noremap = true, desc = "Replace word below cursor" } + "n", + "s", + [[:%s/\<\>//gI]], + { noremap = true, desc = "Replace word below cursor" } ) -- Apply conform.nvim formatting on keypress (same as on save) vim.keymap.set({ "n", "v" }, "o", function() - local conform = require("conform") - conform.format({ - lsp_fallback = true, - async = false, - timeout_ms = 500, - }) + local conform = require("conform") + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 500, + }) end, { desc = "Format file or range (in visual mode)" }) -- Toggle zen-mode.nvim @@ -104,27 +104,37 @@ vim.keymap.set("n", "z", ":ZenMode") -- Go to next diagnostic item (any severity) vim.keymap.set({ "n", "v" }, "da", function() - vim.diagnostic.goto_next({}) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.goto_next({}) + vim.api.nvim_feedkeys("zz", "n", false) end, { desc = "Go to next diagnostic" }) -- Go to next diagnostic item (error severity) vim.keymap.set({ "n", "v" }, "de", function() - vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) + vim.api.nvim_feedkeys("zz", "n", false) end, { desc = "Go to next error diagnostic" }) -- Go to next diagnostic item (warning severity) vim.keymap.set({ "n", "v" }, "dw", function() - vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.WARN }) - vim.api.nvim_feedkeys("zz", "n", false) + vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.WARN }) + vim.api.nvim_feedkeys("zz", "n", false) end, { desc = "Go to next warning diagnostic" }) -- Toggle LSP diagnostics vim.keymap.set({ "n", "v" }, "dd", function() - vim.diagnostic.enable(not vim.diagnostic.is_enabled()) + vim.diagnostic.enable(not vim.diagnostic.is_enabled()) end, { desc = "Turn diagnostics on/off" }) -- Toggle trouble (for document) --vim.keymap.set("n", "qq", ":TroubleToggle") --vim.keymap.set("n", "qq", "Trouble diagnostics toggle") + +-- By default, show virtual_text and hide virtual_lines. +-- This keymap allows to do the opposite. Can be useful when there are multiple +-- severities on the same line +vim.keymap.set("n", "tdd", function() + vim.diagnostic.config({ + virtual_lines = not vim.diagnostic.config().virtual_lines, + virtual_text = not vim.diagnostic.config().virtual_text, + }) +end, { desc = "Toggle diagnostic virtual lines and virtual text" })