vim/telescope: simplify creation of custom mappings

This commit is contained in:
Fernando Schauenburg 2023-08-12 02:35:21 +02:00
parent 1edab453ed
commit 0ef1cba81f
2 changed files with 59 additions and 95 deletions

View file

@ -1,18 +1,3 @@
local actions = require('fschauen.telescope').actions
local mappings = {
['<c-j>'] = actions.cycle_history_next,
['<c-k>'] = actions.cycle_history_prev,
['<s-down>'] = actions.preview_scrolling_down,
['<s-up>'] = actions.preview_scrolling_up,
['<c-y>'] = actions.cycle_layout_next,
['<c-o>'] = actions.toggle_mirror,
['<c-c>'] = actions.close,
['<c-q>'] = actions.smart_send_to_qflist_and_open,
['<c-l>'] = actions.smart_send_to_loclist_and_open,
['<c-b>'] = actions.smart_open_with_trouble
}
return {
{
'nvim-telescope/telescope.nvim',
@ -24,55 +9,75 @@ return {
},
cmd = 'Telescope',
keys = require('fschauen.keymap').telescope,
opts = {
defaults = {
mappings = {
i = mappings,
n = mappings,
},
opts = function()
local actions = require('telescope.actions')
local layout = require('telescope.actions.layout')
local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {}
prompt_prefix = '', -- Alternatives: 
selection_caret = '', -- Alternatives:  ➔ 
local mappings = {
['<c-j>'] = actions.cycle_history_next,
['<c-k>'] = actions.cycle_history_prev,
['<s-down>'] = actions.preview_scrolling_down,
['<s-up>'] = actions.preview_scrolling_up,
['<c-y>'] = layout.cycle_layout_next,
['<c-o>'] = layout.toggle_mirror,
['<c-c>'] = actions.close,
['<c-q>'] = actions.smart_send_to_qflist + actions.open_qflist,
['<c-l>'] = actions.smart_send_to_loclist + actions.open_loclist,
['<c-b>'] = trouble.smart_open_with_trouble,
}
multi_icon = '󰄬 ', -- Alternatives: 󰄬  
scroll_strategy = 'limit', -- Don't wrap around in results.
dynamic_preview_title = true,
layout_strategy = 'flex',
layout_config = {
width = 0.9,
height = 0.9,
flex = { flip_columns = 130 },
horizontal = { preview_width = 0.5, preview_cutoff = 130 },
vertical = { preview_height = 0.5 },
},
cycle_layout_list = { 'horizontal', 'vertical' },
},
pickers = {
buffers = {
return {
defaults = {
mappings = {
n = {
x = actions.delete_buffer,
i = mappings,
n = mappings,
},
prompt_prefix = '', -- Alternatives: 
selection_caret = '', -- Alternatives:  ➔ 
multi_icon = '󰄬 ', -- Alternatives: 󰄬  
scroll_strategy = 'limit', -- Don't wrap around in results.
dynamic_preview_title = true,
layout_strategy = 'flex',
layout_config = {
width = 0.9,
height = 0.9,
flex = { flip_columns = 130 },
horizontal = { preview_width = 0.5, preview_cutoff = 130 },
vertical = { preview_height = 0.5 },
},
cycle_layout_list = { 'horizontal', 'vertical' },
},
pickers = {
buffers = {
mappings = {
n = {
x = actions.delete_buffer,
},
},
},
colorscheme = {
theme = 'dropdown',
},
spell_suggest = {
theme = 'cursor',
},
},
colorscheme = {
theme = 'dropdown',
extensions = {
file_browser = {
theme = 'ivy'
},
},
spell_suggest = {
theme = 'cursor',
},
},
extensions = {
file_browser = {
theme = 'ivy'
},
},
},
}
end,
config = function(_, opts)
require('telescope').setup(opts)
require('telescope').load_extension 'fzf'
vim.api.nvim_create_autocmd('User', {
desc = 'Enable line number in Telescope previewers.',
group = vim.api.nvim_create_augroup('fschauen.telescope', { clear = true } ),

View file

@ -1,47 +1,6 @@
M = {}
local builtin = function() return require('telescope.builtin') end
local actions = function() return require('telescope.actions') end
local layout = function() return require('telescope.actions.layout') end
M.actions = {
cycle_history_next = function(...)
actions().cycle_history_next(...)
end,
cycle_history_prev = function(...)
actions().cycle_history_prev(...)
end,
preview_scrolling_down = function(...)
actions().preview_scrolling_down(...)
end,
preview_scrolling_up = function(...)
actions().preview_scrolling_up(...)
end,
cycle_layout_next = function(...)
layout().cycle_layout_next(...)
end,
toggle_mirror = function(...)
layout().toggle_mirror(...)
end,
close = function(...)
actions().close(...)
end,
delete_buffer = function(...)
actions().delete_buffer(...)
end,
smart_send_to_qflist_and_open = function(...)
actions().smart_send_to_qflist(...)
actions().open_qflist(...)
end,
smart_send_to_loclist_and_open = function(...)
actions().smart_send_to_loclist(...)
actions().open_loclist(...)
end,
smart_open_with_trouble = function(...)
local trouble = vim.F.npcall(require, 'trouble.providers.telescope')
if trouble then trouble.smart_open_with_trouble(...) end
end,
}
local config_builtin = function(picker, opts)
return function(title)