vim/telescope: make configuration more concise and readable
This commit is contained in:
parent
f5f91c8dc6
commit
1e372c559b
1 changed files with 47 additions and 64 deletions
|
@ -2,9 +2,8 @@ local config = function()
|
||||||
local telescope = require 'telescope'
|
local telescope = require 'telescope'
|
||||||
local actions = require 'telescope.actions'
|
local actions = require 'telescope.actions'
|
||||||
local actions_layout = require 'telescope.actions.layout'
|
local actions_layout = require 'telescope.actions.layout'
|
||||||
local builtin = require 'telescope.builtin'
|
|
||||||
|
|
||||||
local keymap = {
|
local mappings = {
|
||||||
['<c-l>'] = actions_layout.cycle_layout_next,
|
['<c-l>'] = actions_layout.cycle_layout_next,
|
||||||
['<c-o>'] = actions_layout.toggle_mirror,
|
['<c-o>'] = actions_layout.toggle_mirror,
|
||||||
['<c-q>'] = actions.smart_send_to_qflist + actions.open_qflist,
|
['<c-q>'] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||||
|
@ -17,22 +16,6 @@ local config = function()
|
||||||
['<c-k>'] = actions.cycle_history_prev,
|
['<c-k>'] = actions.cycle_history_prev,
|
||||||
}
|
}
|
||||||
|
|
||||||
local titles = {
|
|
||||||
git_commits = ' Commits ',
|
|
||||||
buffers = ' Buffers ',
|
|
||||||
find_files = ' Files ',
|
|
||||||
help_tags = ' Help tags ',
|
|
||||||
keymaps = ' Keymaps ',
|
|
||||||
live_grep = ' Live grep ',
|
|
||||||
vim_options = ' Vim options ',
|
|
||||||
man_pages = ' Man pages ',
|
|
||||||
all_files = ' ALL Files ',
|
|
||||||
dotfiles = ' Find dotfiles ',
|
|
||||||
grep = ' Grep: %s ',
|
|
||||||
treesitter = ' Treesitter Symbols',
|
|
||||||
current_buffer_fuzzy_find = ' Current buffer',
|
|
||||||
}
|
|
||||||
|
|
||||||
telescope.setup {
|
telescope.setup {
|
||||||
defaults = {
|
defaults = {
|
||||||
prompt_prefix = ' ❯ ',
|
prompt_prefix = ' ❯ ',
|
||||||
|
@ -67,24 +50,11 @@ local config = function()
|
||||||
},
|
},
|
||||||
|
|
||||||
mappings = {
|
mappings = {
|
||||||
i = keymap,
|
i = mappings,
|
||||||
n = keymap,
|
n = mappings,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
pickers = {
|
|
||||||
buffers = { prompt_title = titles.buffers },
|
|
||||||
find_files = { prompt_title = titles.find_files },
|
|
||||||
git_commits = { prompt_title = titles.git_commits },
|
|
||||||
help_tags = { prompt_title = titles.help_tags },
|
|
||||||
keymaps = { prompt_title = titles.keymaps },
|
|
||||||
live_grep = { prompt_title = titles.live_grep },
|
|
||||||
vim_options = { prompt_title = titles.vim_options },
|
|
||||||
man_pages = { prompt_title = titles.man_pages },
|
|
||||||
treesitter = { prompt_title = titles.treesitter },
|
|
||||||
current_buffer_fuzzy_find = { prompt_title = titles.current_buffer_fuzzy_find },
|
|
||||||
},
|
|
||||||
|
|
||||||
extensions = {
|
extensions = {
|
||||||
file_browser = {
|
file_browser = {
|
||||||
theme = 'ivy',
|
theme = 'ivy',
|
||||||
|
@ -100,54 +70,67 @@ local config = function()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
telescope.load_extension 'file_browser'
|
local builtin = require 'telescope.builtin'
|
||||||
telescope.load_extension 'fzf'
|
|
||||||
|
|
||||||
local get_selected_text = require('user.util').get_selected_text
|
|
||||||
|
|
||||||
local custom = {
|
local custom = {
|
||||||
all_files = function()
|
all_files = function(opts)
|
||||||
builtin.find_files {
|
builtin.find_files(vim.tbl_extend('keep', opts or {}, {
|
||||||
prompt_title = titles.all_files,
|
|
||||||
hidden = true,
|
hidden = true,
|
||||||
no_ignore = true,
|
no_ignore = true,
|
||||||
no_ignore_parent = true,
|
no_ignore_parent = true,
|
||||||
}
|
}))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
dotfiles = function()
|
dotfiles = function(opts)
|
||||||
builtin.find_files {
|
builtin.find_files(vim.tbl_extend('keep', opts or {}, {
|
||||||
prompt_title = titles.dotfiles,
|
|
||||||
cwd = '~/.dotfiles',
|
cwd = '~/.dotfiles',
|
||||||
hidden = true,
|
hidden = true,
|
||||||
}
|
}))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
grep = function()
|
grep = function(_)
|
||||||
local selected = get_selected_text()
|
local selected = require('user.util').get_selected_text()
|
||||||
builtin.grep_string {
|
builtin.grep_string {
|
||||||
prompt_title = string.format(titles.grep, selected),
|
prompt_title = string.format(' Grep: %s ', selected),
|
||||||
search = selected,
|
search = selected,
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
here = function(opts) builtin.current_buffer_fuzzy_find(opts) end,
|
||||||
}
|
}
|
||||||
|
|
||||||
local map = vim.keymap.set
|
local map = function(keymap)
|
||||||
map('n', '<leader>fa', custom.all_files, { desc = ' [F]ind [A]ll Files in $PWD' })
|
for _, r in ipairs(keymap) do
|
||||||
map('n', '<leader>fb', builtin.buffers, { desc = ' [F]ind [B]uffers' })
|
local modes, lhs, picker, title, desc = r[1], r[2], r[3], r[4], r[5]
|
||||||
map('n', '<leader>fc', builtin.git_commits, { desc = ' [F]ind [C]ommits' })
|
local rhs = function() picker { prompt_title = title } end
|
||||||
map('n', '<leader>fd', custom.dotfiles, { desc = ' [F]ind [D]otfiles' })
|
vim.keymap.set(modes, lhs, rhs, { desc = desc })
|
||||||
map('n', '<leader>ff', builtin.find_files, { desc = ' [F]ind [F]iles in $PWD' })
|
end
|
||||||
map('n', '<leader>fg', builtin.live_grep, { desc = ' [F]ind with [G]rep in $PWD' })
|
end
|
||||||
map('n', '<leader>fh', builtin.current_buffer_fuzzy_find, { desc = ' [F]ind [H]ere' })
|
|
||||||
map('n', '<leader>fk', builtin.keymaps, { desc = ' [F]ind [K]eymaps' })
|
map {
|
||||||
map('n', '<leader>fm', builtin.man_pages, { desc = ' [F]ind [M]an pages' })
|
-- ╭────╮ ╭────╮ ╭──────╮ ╭────────────╮ ╭───────────────────╮
|
||||||
map('n', '<leader>fo', builtin.vim_options, { desc = ' [F]ind vim [O]ptions' })
|
-- │mode│ │keys│ │picker│ │prompt title│ │mapping description│
|
||||||
map('n', '<leader>fs', custom.grep, { desc = ' [F]ind [S]tring' })
|
-- ╰────╯ ╰────╯ ╰──────╯ ╰────────────╯ ╰───────────────────╯
|
||||||
map('v', '<leader>fs', custom.grep, { desc = ' [F]ind visual [S]election' })
|
{ 'n', '<leader>fa', custom.all_files , ' ALL Files ' , ' [F]ind [A]ll Files in $PWD' },
|
||||||
map('n', '<leader>ft', builtin.treesitter, { desc = ' [F]ind [T]reesitter Symbols' })
|
{ 'n', '<leader>fb', builtin.buffers , ' Buffers ' , ' [F]ind [B]uffers' },
|
||||||
map('n', '<leader>f?', builtin.help_tags, { desc = ' [F]ind Help tags [?]' })
|
{ 'n', '<leader>fc', builtin.git_commits , ' Commits ' , ' [F]ind [C]ommits' },
|
||||||
map('n', '<leader>br', '<cmd>Telescope file_browser<cr>', { desc = ' file [BR]owser' })
|
{ 'n', '<leader>fd', custom.dotfiles , ' Find dotfiles ' , ' [F]ind [D]otfiles' },
|
||||||
|
{ 'n', '<leader>ff', builtin.find_files , ' Files ' , ' [F]ind [F]iles in $PWD' },
|
||||||
|
{ 'n', '<leader>fg', builtin.live_grep , ' Live grep ' , ' [F]ind with [G]rep in $PWD' },
|
||||||
|
{ 'n', '<leader>fh', custom.here , ' Current buffer ' , ' [F]ind [H]ere' },
|
||||||
|
{ 'n', '<leader>fk', builtin.keymaps , ' Keymaps ' , ' [F]ind [K]eymaps' },
|
||||||
|
{ 'n', '<leader>fm', builtin.man_pages , ' Man pages ' , ' [F]ind [M]an pages' },
|
||||||
|
{ 'n', '<leader>fo', builtin.vim_options , ' Vim options ' , ' [F]ind vim [O]ptions' },
|
||||||
|
{ 'n', '<leader>fs', custom.grep, nil , ' [F]ind [S]tring' },
|
||||||
|
{ 'n', '<leader>fs', custom.grep, nil , ' [F]ind visual [S]election' },
|
||||||
|
{ 'n', '<leader>ft', builtin.treesitter , ' Treesitter Symbols ' , ' [F]ind [T]reesitter Symbols' },
|
||||||
|
{ 'n', '<leader>f?', builtin.help_tags , ' Help tags ' , ' [F]ind Help tags [?]' },
|
||||||
|
}
|
||||||
|
|
||||||
|
telescope.load_extension 'fzf'
|
||||||
|
|
||||||
|
telescope.load_extension 'file_browser'
|
||||||
|
vim.keymap.set('n', '<leader>br', '<cmd>Telescope file_browser<cr>', { desc = ' file [BR]owser' })
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Reference in a new issue