Created
December 12, 2024 19:52
-
-
Save roycrippen4/3c45f6a36fad4b14778c37fe6194c37f to your computer and use it in GitHub Desktop.
Load plugin before opening its help via telescope.nvim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Adapt code to package manager of your choice. | |
-- I am using lazy.nvim in this example | |
local help_tag_mapping = { | |
['<CR>'] = function(prompt_bufnr) | |
local selection = require('telescope.actions.state').get_selected_entry() | |
if not selection then | |
return | |
end | |
local doc_path = selection.filename or selection.path | |
require('telescope.actions').close(prompt_bufnr) | |
local plugin_to_load = nil | |
for _, p in pairs(require('lazy').plugins()) do | |
if doc_path:find(p.dir, 1, true) then | |
plugin_to_load = p.name | |
break | |
end | |
end | |
-- some plugin names don't match the name you would require | |
-- For example, conform.nvim would be loaded via `require("conform")` NOT `require("conform.nvim")` | |
-- This can be different for every plugin, so you'll need to figure this out on your own. | |
local map = { | |
['conform.nvim'] = 'conform', | |
['crates.nvim'] = 'crates', | |
['nvim-scissors'] = 'scissors', | |
} | |
if plugin_to_load then | |
plugin_to_load = map[plugin_to_load] or plugin_to_load | |
pcall(require, plugin_to_load) | |
end | |
vim.cmd('help ' .. selection.value) | |
end, | |
} | |
return { | |
"nvim-telescope/telescope.nvim", | |
dependencies = { --[[ your dependencies ]] }, | |
config = function() | |
require("telescope").setup({ | |
-- Rest of your config | |
pickers = { | |
help_tags = { mappings = { i = help_tag_mapping, n = help_tag_mapping } }, | |
}, | |
}) | |
end, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment