Skip to content

Commit 441805c

Browse files
committed
feat: add buffer keymap when entering hover split
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent 11bd0f5 commit 441805c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lua/hoversplit/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ M.options = {
1010
}
1111

1212
return M
13-
-- vim:ft=lua:ts=4:sts=4:noet:ai:si:sta:
13+
-- vim:ts=4:sts=4:noet:ai:si:sta:

lua/hoversplit/init.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
local config = require("hoversplit.config")
2-
31
local M = {}
42

3+
local config = require("hoversplit.config")
4+
55
M.hover_bufnr = nil ---@type integer|nil
66
M.hover_winid = nil ---@type integer|nil
77
M.orig_winid = nil ---@type integer|nil
@@ -49,6 +49,18 @@ function M.create_hover_split(vertical, remain_focused)
4949
M.orig_winid = vim.api.nvim_get_current_win()
5050
M.hover_bufnr = vim.api.nvim_create_buf(false, true)
5151

52+
vim.api.nvim_create_autocmd("BufEnter", {
53+
group = vim.api.nvim_create_augroup("HoverSplitBuffer", { clear = true }),
54+
buffer = M.hover_bufnr,
55+
callback = function(ev)
56+
vim.keymap.set('n', 'q', M.close_hover_split, {
57+
noremap = true,
58+
silent = true,
59+
buffer = ev.buf,
60+
})
61+
end,
62+
})
63+
5264
if not vertical then
5365
M.hover_winid = vim.api.nvim_open_win(M.hover_bufnr, remain_focused, {
5466
focusable = true,
@@ -147,4 +159,4 @@ function M.setup(options)
147159
end
148160

149161
return M
150-
-- vim:ft=lua:ts=4:sts=4:noet:ai:si:sta:
162+
-- vim:ts=4:sts=4:noet:ai:si:sta:

0 commit comments

Comments
 (0)