From 4b1588f253b0b8786d6355e3233adfdcc6eacf40 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 29 Jan 2023 15:15:31 +0100 Subject: [PATCH] nvim: customize most Telescope pickers in the setup() function This is just a refactor to make the code a bit nicer to read. --- config/nvim/after/plugin/telescope.lua | 101 ++++++++++--------------- 1 file changed, 42 insertions(+), 59 deletions(-) diff --git a/config/nvim/after/plugin/telescope.lua b/config/nvim/after/plugin/telescope.lua index cacefff..2cc278f 100644 --- a/config/nvim/after/plugin/telescope.lua +++ b/config/nvim/after/plugin/telescope.lua @@ -46,12 +46,21 @@ telescope.setup { i = vim.tbl_extend('force', common_mappings, { [''] = actions.cycle_history_next, [''] = actions.cycle_history_prev, - }), n = common_mappings, }, }, + pickers = { + buffers = { prompt_title = ' ﬘ Find buffers ' }, + find_files = { prompt_title = '  Find files ' }, + git_commits = { prompt_title = '  Find commits ' }, + help_tags = { prompt_title = ' ﬤ Find help tags ' }, + keymaps = { prompt_title = '  Find keymaps ' }, + live_grep = { prompt_title = ' 🔍 Grep ' }, + vim_options = { prompt_title = '  Find options ' }, + }, + extensions = { file_browser = { theme = 'ivy', @@ -67,8 +76,40 @@ telescope.setup { }, } +local builtin = require 'telescope.builtin' + +local custom = { + dotfiles = function() + builtin.find_files { + prompt_title = '  Find dotfiles ', + cwd = '~/.dotfiles', + hidden = true, + } + end, + + man_pages = function() + builtin.man_pages { + prompt_title = '  Find man pages ', + sections = { 'ALL' }, + man_cmd = { "apropos", ".*" } + } + end, +} + local map = vim.keymap.set +map('n', 'fb', builtin.buffers, { desc = 'Telescope: find buffers' }) +map('n', 'fc', builtin.git_commits, { desc = 'Telescope: find commits' }) +map('n', 'fd', custom.dotfiles, { desc = 'Telescope: find in dotfiles' }) +map('n', 'ff', builtin.find_files, { desc = 'Telescope: find files in $PWD' }) +map('n', 'fg', builtin.live_grep, { desc = 'Telescope: live grep in $PWD' }) +map('n', 'fh', builtin.help_tags, { desc = 'Telescope: find help tags' }) +map('n', 'fk', builtin.keymaps, { desc = 'Telescope: find keymaps' }) +map('n', 'fm', custom.man_pages, { desc = 'Telescope: find man pages' }) +map('n', 'fo', builtin.vim_options, { desc = 'Telescope: find vim options' }) + + + local loaded_file_browser, _ = pcall(telescope.load_extension, 'file_browser') if loaded_file_browser then map('n', 'br', 'Telescope file_browser') @@ -76,61 +117,3 @@ else vim.notify('Telescope file_browser not installed!', vim.log.levels.WARN) end -local builtin = require 'telescope.builtin' - -map('n', 'fb', - function() builtin.buffers { prompt_title = ' ﬘ Find buffers ' } end, - { desc = 'Telescope: find buffers' }) - -map('n', 'fc', - function() builtin.git_commits { prompt_title = '  Find commits ' } end, - { desc = 'Telescope: find commits' }) - -map('n', 'fd', - function() - builtin.find_files { - prompt_title = '  Find dotfiles ', - cwd = '~/.dotfiles', - hidden = true, - } - end, - { desc = 'Telescope: find in dotfiles' }) - -map('n', 'ff', - function() builtin.find_files { prompt_title = '  Find files ' } end, - { desc = 'Find files in $PWD (Telescope)' }) - -map('n', 'fg', - function() builtin.live_grep { prompt_title = ' 🔍 Grep ' } end, - { desc = 'Live grep in $PWD (Telescope)' }) - -map('n', 'fh', - function() builtin.help_tags { prompt_title = ' ﬤ Find help tags ' } end, - { desc = 'Telescope: find help tags' }) - -map('n', 'fk', - function() builtin.keymaps { prompt_title = '  Find keymaps ' } end, - { desc = 'Telescope: find keymaps' }) - -map('n', 'fm', - function() - builtin.man_pages { - prompt_title = '  Find man pages ', - sections = { 'ALL' }, - man_cmd = { "apropos", ".*" } - } - end, - { desc = 'Telescope: find man pages' }) - -map('n', 'fo', - function() - builtin.vim_options { - prompt_title = '  Find options ', - layout_config = { - width = 0.75, - height = 0.8, - } - } - end, - { desc = 'Telescope: find options' }) -