Skip to content

Commit 9584a79

Browse files
committed
feat(mappings): support custom mappings
1 parent ca986ee commit 9584a79

3 files changed

Lines changed: 48 additions & 28 deletions

File tree

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
<!-- vim-markdown-toc GFM -->
1111

12-
* [Intro](#intro)
13-
* [Requirements](#requirements)
14-
* [Installation](#installation)
15-
* [Usage](#usage)
16-
* [Configuration](#configuration)
17-
* [Key Bindings](#key-bindings)
18-
* [Feedback](#feedback)
12+
- [Intro](#intro)
13+
- [Requirements](#requirements)
14+
- [Installation](#installation)
15+
- [Usage](#usage)
16+
- [Configuration](#configuration)
17+
- [Key Bindings](#key-bindings)
18+
- [Feedback](#feedback)
1919

2020
<!-- vim-markdown-toc -->
2121

@@ -93,6 +93,17 @@ require('flygrep').setup({
9393
},
9494
},
9595
timeout = 200,
96+
mappings = {
97+
next_item = '<Tab>',
98+
previous_item = '<S-Tab>',
99+
toggle_fix_string = '<C-e>',
100+
toggle_hidden_file = '<C-h>',
101+
toggle_preview_win = '<C-p>',
102+
open_item_edit = '<Enter>',
103+
open_item_split = '<C-s>',
104+
open_item_vsplit = '<C-v>',
105+
open_item_tabedit = '<C-t>',
106+
},
96107
command = {
97108
execute = 'rg',
98109
default_opts = {
@@ -125,16 +136,16 @@ require('flygrep').setup({
125136

126137
## Key Bindings
127138

128-
| Key bindings | descretion |
129-
| -------------------- | ---------------------------------- |
130-
| `<Enter>` | open cursor item |
131-
| `<Tab>` or `<C-j>` | next item |
132-
| `<S-Tab>` or `<C-k>` | previous item |
133-
| `<C-s>` | open item in split window |
134-
| `<C-v>` | open item in vertical split window |
135-
| `<C-t>` | open item in new tabpage |
136-
| `<C-p>` | toggle preview window |
137-
| `<C-h>` | toggle display hidden files |
139+
| Key bindings | descretion |
140+
| ------------ | ---------------------------------- |
141+
| `<Enter>` | open cursor item |
142+
| `<Tab>` | next item |
143+
| `<S-Tab>` | previous item |
144+
| `<C-s>` | open item in split window |
145+
| `<C-v>` | open item in vertical split window |
146+
| `<C-t>` | open item in new tabpage |
147+
| `<C-p>` | toggle preview window |
148+
| `<C-h>` | toggle display hidden files |
138149

139150
## Feedback
140151

lua/flygrep/config.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ local M = {}
22

33
local default_config = {
44
timeout = 200,
5+
mappings = {
6+
next_item = '<Tab>',
7+
previous_item = '<S-Tab>',
8+
toggle_fix_string = '<C-e>',
9+
toggle_hidden_file = '<C-h>',
10+
toggle_preview_win = '<C-p>',
11+
open_item_edit = '<Enter>',
12+
open_item_split = '<C-s>',
13+
open_item_vsplit = '<C-v>',
14+
open_item_tabedit = '<C-t>',
15+
},
516
color_templete = {
617
a = {
718
fg = '#2c323c',

lua/flygrep/init.lua

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,16 @@ local function open_win()
424424
vim.api.nvim_win_set_cursor(0, { linenr, colum })
425425
vim.o.mouse = saved_mouse_opt
426426
end
427-
vim.keymap.set('i', '<Enter>', function()
427+
vim.keymap.set('i', config.mappings.open_item_edit, function()
428428
open_item('edit')
429429
end, { buffer = prompt_bufid })
430-
vim.keymap.set('i', '<C-v>', function()
430+
vim.keymap.set('i', config.mappings.open_item_vsplit, function()
431431
open_item('vsplit')
432432
end, { buffer = prompt_bufid })
433-
vim.keymap.set('i', '<C-s>', function()
433+
vim.keymap.set('i', config.mappings.open_item_split, function()
434434
open_item('split')
435435
end, { buffer = prompt_bufid })
436-
vim.keymap.set('i', '<C-t>', function()
436+
vim.keymap.set('i', config.mappings.open_item_tabedit, function()
437437
open_item('tabedit')
438438
end, { buffer = prompt_bufid })
439439

@@ -448,19 +448,17 @@ local function open_win()
448448
end
449449

450450
-- 使用 Tab/Shift-Tab and Ctrl-jk 上下移动搜素结果
451-
vim.keymap.set('i', '<Tab>', next_item, { buffer = prompt_bufid })
452-
vim.keymap.set('i', '<C-j>', next_item, { buffer = prompt_bufid })
453-
vim.keymap.set('i', '<S-Tab>', previous_item, { buffer = prompt_bufid })
454-
vim.keymap.set('i', '<C-k>', previous_item, { buffer = prompt_bufid })
455-
vim.keymap.set('i', '<C-e>', function()
451+
vim.keymap.set('i', config.mappings.next_item, next_item, { buffer = prompt_bufid })
452+
vim.keymap.set('i', config.mappings.previous_item, previous_item, { buffer = prompt_bufid })
453+
vim.keymap.set('i', config.mappings.toggle_fix_string, function()
456454
toggle_fix_string()
457455
update_result_count()
458456
end, { buffer = prompt_bufid })
459-
vim.keymap.set('i', '<C-h>', function()
457+
vim.keymap.set('i', config.mappings.toggle_hidden_file, function()
460458
toggle_hidden_file()
461459
update_result_count()
462460
end, { buffer = prompt_bufid })
463-
vim.keymap.set('i', '<C-p>', function()
461+
vim.keymap.set('i', config.mappings.toggle_preview_win, function()
464462
toggle_preview_win()
465463
end, { buffer = prompt_bufid })
466464

0 commit comments

Comments
 (0)