Skip to content

Commit d41c48a

Browse files
authored
feat: close float win more easily when not needed (#433)
1 parent 9d7d356 commit d41c48a

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lua/config/lsp.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ vim.api.nvim_create_autocmd("LspAttach", {
6161
end, { desc = "go to definition" })
6262
map("n", "<C-]>", vim.lsp.buf.definition)
6363
map("n", "K", function()
64-
vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 }
64+
vim.lsp.buf.hover {
65+
border = "single",
66+
max_height = 20,
67+
max_width = 130,
68+
close_events = { "CursorMoved", "BufLeave", "WinLeave", "LSPDetach" },
69+
}
6570
end)
6671
map("n", "<C-k>", vim.lsp.buf.signature_help)
6772
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })

lua/diagnostic-conf.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ diagnostic.config {
2020
header = "Diagnostics:",
2121
prefix = " ",
2222
border = "single",
23+
max_height = 10,
24+
max_width = 130,
25+
close_events = { "CursorMoved", "BufLeave", "WinLeave" },
2326
},
2427
}
2528

@@ -58,7 +61,7 @@ api.nvim_create_autocmd("CursorHold", {
5861
local cursor_pos = api.nvim_win_get_cursor(0)
5962

6063
if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then
61-
diagnostic.open_float { width = 100 }
64+
diagnostic.open_float {}
6265
end
6366

6467
vim.b.diagnostics_pos = cursor_pos

lua/mappings.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,9 @@ end)
240240
keymap.set("n", "Q", "q", {
241241
desc = "Record macro",
242242
})
243+
244+
keymap.set("n", "<Esc>", function()
245+
vim.cmd("fclose!")
246+
end, {
247+
desc = "close floating win",
248+
})

0 commit comments

Comments
 (0)