From 5ac4d1b8217545b7fa6324bef72c9883d971c593 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 23 Nov 2022 15:20:09 +0100 Subject: [PATCH] refactor(nvim): set telescope keymaps using lua callbacks --- home-manager/neovim/keymaps.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/home-manager/neovim/keymaps.lua b/home-manager/neovim/keymaps.lua index cbeff65..8f5a285 100644 --- a/home-manager/neovim/keymaps.lua +++ b/home-manager/neovim/keymaps.lua @@ -20,13 +20,28 @@ nnoremap("g", ":0Git") nnoremap("G", ":GV --all") -- telescope -nnoremap("ff", "Telescope find_files theme=dropdown") -nnoremap("fb", "Telescope buffers theme=dropdown") -nnoremap("fg", "Telescope git_files theme=dropdown") -nnoremap("fp", "Telescope projects theme=dropdown") -nnoremap("fs", "Telescope lsp_dynamic_workspace_symbols theme=dropdown") -nnoremap("", "Telescope grep_string") -nnoremap("", "Telescope live_grep") +local telescope = require("telescope.builtin") +local telescope_themes = require("telescope.themes") +local telescope_projects = require("telescope").extensions.projects + +local function map_telescope(key, telescope_function) + vim.api.nvim_set_keymap("n", key, "", { + noremap = true, + callback = function() + local theme = telescope_themes.get_dropdown({ layout_config = { width = 0.9 } }) + telescope_function(theme) + end, + }) + +end + +map_telescope("ff", telescope.find_files) +map_telescope("fb", telescope.buffers) +map_telescope("fg", telescope.git_files) +map_telescope("fp", telescope_projects.projects) +map_telescope("fs", telescope.lsp_dynamic_workspace_symbols) +map_telescope("", telescope.grep_string) +map_telescope("", telescope.live_grep) -- terminal vim.api.nvim_create_autocmd("TermOpen", {