neovim: open multiple files in telescope

https://github.com/nvim-telescope/telescope.nvim/issues/1048
This commit is contained in:
teutat3s 2024-08-21 16:02:36 +02:00
parent a4bebfef29
commit 195c81f8b1
Signed by: teutat3s
GPG key ID: 4FA1D3FA524F22C1

View file

@ -62,6 +62,26 @@ nmap <leader>n :NnnPicker %<CR>
nmap <leader>N :NnnPicker<CR> nmap <leader>N :NnnPicker<CR>
lua <<EOF lua <<EOF
local multiopen = function(prompt_bufnr)
local picker = require('telescope.actions.state').get_current_picker(prompt_bufnr)
local multi = picker:get_multi_selection()
if vim.tbl_isempty(multi) then
require('telescope.actions').select_default(prompt_bufnr)
return
end
require('telescope.actions').close(prompt_bufnr)
for _, entry in pairs(multi) do
local filename = entry.filename or entry.value
local lnum = entry.lnum or 1
local lcol = entry.col or 1
if filename then
vim.cmd(string.format("tabnew +%d %s", lnum, filename))
vim.cmd(string.format("normal! %dG%d|", lnum, lcol))
end
end
end
local actions = require("telescope.actions") local actions = require("telescope.actions")
local telescope = require("telescope") local telescope = require("telescope")
telescope.setup{ telescope.setup{
@ -74,6 +94,9 @@ telescope.setup{
["K"] = actions.move_to_bottom, ["K"] = actions.move_to_bottom,
["<C-c>"] = actions.close, ["<C-c>"] = actions.close,
}, },
i = {
['<CR>'] = multiopen,
}
}, },
}, },
pickers = { pickers = {