update:nvim code diag

This commit is contained in:
2026-05-27 00:02:53 +09:00
parent 87fba5d240
commit 1458d211b1
2 changed files with 45 additions and 7 deletions

View File

@@ -62,6 +62,31 @@ function M.setup()
vim.diagnostic.config({ virtual_text = false })
local function pause_diagnostic_float_until_move(bufnr)
vim.b[bufnr].pause_diagnostic_float = true
vim.api.nvim_create_autocmd({ "CursorMoved", "InsertEnter", "BufLeave" }, {
buffer = bufnr,
once = true,
callback = function()
vim.b[bufnr].pause_diagnostic_float = false
end,
})
end
local diag_float_group = vim.api.nvim_create_augroup("UserDiagnosticFloat", { clear = true })
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
group = diag_float_group,
callback = function(ev)
if vim.b[ev.buf].pause_diagnostic_float then
return
end
vim.diagnostic.open_float(nil, {
focusable = false,
scope = "line",
})
end,
})
local function text_format(symbol)
local fragments = {}
@@ -118,7 +143,10 @@ function M.setup()
end
map("n", "gD", vim.lsp.buf.declaration, "LSP declaration")
map("n", "K", vim.lsp.buf.hover, "LSP hover")
map("n", "K", function()
pause_diagnostic_float_until_move(bufnr)
vim.lsp.buf.hover()
end, "LSP hover")
map("n", "gi", vim.lsp.buf.implementation, "LSP implementation")
map("n", "<C-k>", vim.lsp.buf.signature_help, "LSP signature help")
map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, "LSP add workspace folder")

View File

@@ -3,12 +3,6 @@ vim.keymap.set("n", "<leader>E", "<cmd>Ex<CR>", { desc = "Open netrw" })
vim.keymap.set("n", "<leader>ER", "<cmd>bw<CR>", { desc = "Close buffer" })
vim.keymap.set("n", "<leader>sr", ":cd %:p:h<CR>", { desc = "Set cwd to file dir" })
-- split navigation
vim.keymap.set("n", "<A-Left>", "<C-w>h")
vim.keymap.set("n", "<A-Down>", "<C-w>j")
vim.keymap.set("n", "<A-Up>", "<C-w>k")
vim.keymap.set("n", "<A-Right>", "<C-w>l")
-- netrw duplicate helper (<leader>d)
vim.api.nvim_create_autocmd("FileType", {
pattern = "netrw",
@@ -26,6 +20,12 @@ vim.api.nvim_create_autocmd("FileType", {
end,
})
-- split navigation
vim.keymap.set("n", "<A-Left>", "<C-w>h")
vim.keymap.set("n", "<A-Down>", "<C-w>j")
vim.keymap.set("n", "<A-Up>", "<C-w>k")
vim.keymap.set("n", "<A-Right>", "<C-w>l")
-- buffer history (per-tab)
local hist_by_tab = {}
local navigating = false
@@ -163,3 +163,13 @@ vim.keymap.set("n", "<leader>x", function()
end
end
end, { desc = "Close floating windows" })
-- Map Ctrl + Left Click to open the link under the cursor
vim.keymap.set("n", "<C-LeftMouse>", function()
-- Get the word/URL under the mouse click
local cursor_pos = vim.fn.getmousepos()
vim.api.nvim_win_set_cursor(cursor_pos.winid, {cursor_pos.line, cursor_pos.column - 1})
-- Trigger the native open function
vim.ui.open(vim.fn.expand("<cfile>"))
end, { desc = "Open link under cursor with Ctrl+Click" })