Skip to content

Instantly share code, notes, and snippets.

@fl3pp
Created January 30, 2023 14:15
Show Gist options
  • Save fl3pp/643683616f8304cf61c249f3d6c60eec to your computer and use it in GitHub Desktop.
Save fl3pp/643683616f8304cf61c249f3d6c60eec to your computer and use it in GitHub Desktop.
Floating help window for Neovim
function FloatingHelp(subject)
local stats = vim.api.nvim_list_uis()[1]
local width = math.ceil(stats.width * 0.8);
local height = math.ceil(stats.height * 0.8);
local buf = vim.api.nvim_create_buf(false, true)
local winConfig = {
relative = 'editor',
width = width,
height = height,
col = math.ceil((stats.width - width) / 2),
row = math.ceil((stats.height - height) / 2) - 1,
border = 'single'
}
local winId = vim.api.nvim_open_win(buf, true, winConfig)
vim.cmd.set('buftype=help')
vim.cmd.help(subject)
end
-- usage: H or Help <topic>. Autocomplete is supported
vim.cmd("command! -nargs=1 -complete=help H :lua FloatingHelp(\"<args>\")<CR>")
vim.cmd("command! -nargs=1 -complete=help Help :lua FloatingHelp(\"<args>\")<CR>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment