neovim: Use Telescope community multi-open binding
This commit is contained in:
parent
e6f3ce6ba7
commit
cbc831a5ca
1 changed files with 110 additions and 20 deletions
|
|
@ -119,7 +119,7 @@ plugins = {
|
||||||
|
|
||||||
local builtin = require('telescope.builtin')
|
local builtin = require('telescope.builtin')
|
||||||
|
|
||||||
find_files = function(opts)
|
local function find_files(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts['hidden'] = true
|
opts['hidden'] = true
|
||||||
return builtin.find_files(opts)
|
return builtin.find_files(opts)
|
||||||
|
|
@ -137,8 +137,97 @@ plugins = {
|
||||||
vim.keymap.set('n', ';b', builtin.buffers)
|
vim.keymap.set('n', ';b', builtin.buffers)
|
||||||
vim.keymap.set('n', ';*', builtin.grep_string)
|
vim.keymap.set('n', ';*', builtin.grep_string)
|
||||||
end,
|
end,
|
||||||
opts = {
|
opts = function(_plugin, _config)
|
||||||
|
local actions = require("telescope.actions")
|
||||||
|
local action_state = require("telescope.actions.state")
|
||||||
|
local transform_mod = require("telescope.actions.mt").transform_mod
|
||||||
|
|
||||||
|
-- https://github.com/nvim-telescope/telescope.nvim/issues/1048#issuecomment-1225975038
|
||||||
|
local function multiopen(prompt_bufnr, method)
|
||||||
|
local method = method or "default"
|
||||||
|
|
||||||
|
local edit_file_cmd_map = {
|
||||||
|
vertical = "vsplit",
|
||||||
|
horizontal = "split",
|
||||||
|
tab = "tabedit",
|
||||||
|
default = "edit",
|
||||||
|
}
|
||||||
|
local edit_buf_cmd_map = {
|
||||||
|
vertical = "vert sbuffer",
|
||||||
|
horizontal = "sbuffer",
|
||||||
|
tab = "tab sbuffer",
|
||||||
|
default = "buffer",
|
||||||
|
}
|
||||||
|
|
||||||
|
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||||
|
local multi_selection = picker:get_multi_selection()
|
||||||
|
|
||||||
|
if #multi_selection > 1 then
|
||||||
|
require("telescope.pickers").on_close_prompt(prompt_bufnr)
|
||||||
|
pcall(vim.api.nvim_set_current_win, picker.original_win_id)
|
||||||
|
|
||||||
|
for i, entry in ipairs(multi_selection) do
|
||||||
|
local filename, row, col
|
||||||
|
|
||||||
|
if entry.path or entry.filename then
|
||||||
|
filename = entry.path or entry.filename
|
||||||
|
|
||||||
|
row = entry.row or entry.lnum
|
||||||
|
col = vim.F.if_nil(entry.col, 1)
|
||||||
|
elseif not entry.bufnr then
|
||||||
|
local value = entry.value
|
||||||
|
if not value then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(value) == "table" then
|
||||||
|
value = entry.display
|
||||||
|
end
|
||||||
|
|
||||||
|
local sections = vim.split(value, ":")
|
||||||
|
|
||||||
|
filename = sections[1]
|
||||||
|
row = tonumber(sections[2])
|
||||||
|
col = tonumber(sections[3])
|
||||||
|
end
|
||||||
|
|
||||||
|
local entry_bufnr = entry.bufnr
|
||||||
|
|
||||||
|
if entry_bufnr then
|
||||||
|
if not vim.api.nvim_buf_get_option(entry_bufnr, "buflisted") then
|
||||||
|
vim.api.nvim_buf_set_option(entry_bufnr, "buflisted", true)
|
||||||
|
end
|
||||||
|
local command = i == 1 and "buffer" or edit_buf_cmd_map[method]
|
||||||
|
pcall(vim.cmd, string.format("%s %s", command, vim.api.nvim_buf_get_name(entry_bufnr)))
|
||||||
|
else
|
||||||
|
local command = i == 1 and "edit" or edit_file_cmd_map[method]
|
||||||
|
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
|
||||||
|
filename = require("plenary.path"):new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd())
|
||||||
|
pcall(vim.cmd, string.format("%s %s", command, filename))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if row and col then
|
||||||
|
pcall(vim.api.nvim_win_set_cursor, 0, { row, col-1 })
|
||||||
|
end
|
||||||
|
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
else
|
||||||
|
actions["select_" .. method](prompt_bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
defaults = {
|
defaults = {
|
||||||
|
mappings = {
|
||||||
|
i = {
|
||||||
|
["<CR>"] = multiopen,
|
||||||
|
},
|
||||||
|
n = {
|
||||||
|
["<CR>"] = multiopen,
|
||||||
|
},
|
||||||
|
},
|
||||||
vimgrep_arguments = {
|
vimgrep_arguments = {
|
||||||
"rg",
|
"rg",
|
||||||
"--color=never",
|
"--color=never",
|
||||||
|
|
@ -150,13 +239,14 @@ plugins = {
|
||||||
-- Include hidden files, but continue ignoring the .git directory itself.
|
-- Include hidden files, but continue ignoring the .git directory itself.
|
||||||
"--hidden",
|
"--hidden",
|
||||||
"--iglob", "!.git",
|
"--iglob", "!.git",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
pickers = {},
|
pickers = {},
|
||||||
extensions = {
|
extensions = {
|
||||||
aerial = {},
|
aerial = {},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"nvim-telescope/telescope-fzf-native.nvim",
|
"nvim-telescope/telescope-fzf-native.nvim",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue