1
Fork 0
satellite/dotfiles/neovim/lua/my/plugins/telescope.lua

90 lines
2.2 KiB
Lua
Raw Normal View History

local mapSilent = require("my.keymaps").mapSilent
local arpeggio = require("my.plugins.arpeggio")
local M = {}
local bindings = {
2022-08-08 16:25:54 +02:00
builtin = {
-- Open files with control + P
find_files = "<c-P>",
2022-08-08 16:25:54 +02:00
-- Search through files with control + F
live_grep = "<c-F>",
2022-08-08 16:25:54 +02:00
-- See diagnostics with space + d
diagnostics = "<Leader>d",
lsp_document_symbols = { chord = 1, key = "lds" },
2022-08-08 16:25:54 +02:00
-- Open a list with all the pickers
builtin = "<Leader>t",
2022-08-08 16:25:54 +02:00
-- List function, var names etc
treesitter = "<Leader>s",
2022-08-08 16:25:54 +02:00
-- Git stuff
git_commits = "<Leader>gj",
git_branches = "<Leader>gk"
},
["extensions.file_browser.file_browser"] = { chord = 1, key = "jp" },
extensions = {
unicode = {
picker = { mode = "i", kind = "dropdown", key = "ui", chord = 1 }
}
2022-08-08 16:25:54 +02:00
}
}
2022-02-22 21:52:01 +01:00
local function setupKeybinds(obj, path)
2022-08-08 16:25:54 +02:00
if path == nil then path = "" end
for name, keybinds in pairs(obj) do
if (type(keybinds) == "table") and keybinds.key == nil then
-- This means we found a table of keybinds, so we go deeper
setupKeybinds(keybinds, path .. "." .. name)
else
local config = keybinds
local pickerArgument = ""
local key = config
local mode = "n"
local bind = mapSilent
2022-08-08 16:25:54 +02:00
if type(config) == "table" then
key = config.key
if config.mode ~= nil then mode = config.mode end
if config.kind ~= nil then
pickerArgument = "require('telescope.themes').get_" ..
config.kind .. "({})"
2022-02-22 21:52:01 +01:00
end
2022-08-08 16:25:54 +02:00
if config.chord then
-- Useful for insert mode bindings
bind = arpeggio.chordSilent
end
end
-- Maps the keybind to the action
bind(mode, key,
"<cmd>lua require('telescope" .. path .. "')." .. name .. "(" ..
pickerArgument .. ")<CR>")
end
2022-08-08 16:25:54 +02:00
end
2022-02-22 21:52:01 +01:00
end
2022-02-22 21:52:01 +01:00
function M.setup()
2022-08-08 16:25:54 +02:00
setupKeybinds(bindings)
2022-02-22 21:52:01 +01:00
2022-08-08 16:25:54 +02:00
local settings = {
defaults = { mappings = { i = { ["<C-h>"] = "which_key" } } },
pickers = { find_files = { hidden = true } },
extensions = {
file_browser = {
mappings = {
-- Comment so this does not get collapsed
2022-02-22 21:52:01 +01:00
}
2022-08-08 16:25:54 +02:00
}
2022-02-22 21:52:01 +01:00
}
2022-08-08 16:25:54 +02:00
}
2022-02-22 21:52:01 +01:00
2022-08-08 16:25:54 +02:00
require("telescope").setup(settings)
require("telescope").load_extension "file_browser"
end
return M