vim/telescope: simplify creation of custom mappings
This commit is contained in:
parent
1edab453ed
commit
0ef1cba81f
2 changed files with 59 additions and 95 deletions
|
@ -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 {
|
return {
|
||||||
{
|
{
|
||||||
'nvim-telescope/telescope.nvim',
|
'nvim-telescope/telescope.nvim',
|
||||||
|
@ -24,7 +9,25 @@ return {
|
||||||
},
|
},
|
||||||
cmd = 'Telescope',
|
cmd = 'Telescope',
|
||||||
keys = require('fschauen.keymap').telescope,
|
keys = require('fschauen.keymap').telescope,
|
||||||
opts = {
|
opts = function()
|
||||||
|
local actions = require('telescope.actions')
|
||||||
|
local layout = require('telescope.actions.layout')
|
||||||
|
local trouble = vim.F.npcall(require, 'trouble.providers.telescope') or {}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
defaults = {
|
defaults = {
|
||||||
mappings = {
|
mappings = {
|
||||||
i = mappings,
|
i = mappings,
|
||||||
|
@ -69,10 +72,12 @@ return {
|
||||||
theme = 'ivy'
|
theme = 'ivy'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
end,
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
require('telescope').setup(opts)
|
require('telescope').setup(opts)
|
||||||
require('telescope').load_extension 'fzf'
|
require('telescope').load_extension 'fzf'
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('User', {
|
vim.api.nvim_create_autocmd('User', {
|
||||||
desc = 'Enable line number in Telescope previewers.',
|
desc = 'Enable line number in Telescope previewers.',
|
||||||
group = vim.api.nvim_create_augroup('fschauen.telescope', { clear = true } ),
|
group = vim.api.nvim_create_augroup('fschauen.telescope', { clear = true } ),
|
||||||
|
|
|
@ -1,47 +1,6 @@
|
||||||
M = {}
|
M = {}
|
||||||
|
|
||||||
local builtin = function() return require('telescope.builtin') end
|
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)
|
local config_builtin = function(picker, opts)
|
||||||
return function(title)
|
return function(title)
|
||||||
|
|
Loading…
Add table
Reference in a new issue