mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 15:19:12 +08:00
feat(quickfix): add undo
key binding
This commit is contained in:
parent
f3df26b6b3
commit
01d493a2b6
@ -40,15 +40,17 @@ Plug 'wsdjeg/quickfix.nvim'
|
||||
| `C` | remove items which filename not match input regex |
|
||||
| `o` | remove items which error description match input regex |
|
||||
| `O` | remove items which error description not match input regex |
|
||||
| `u` | undo last change |
|
||||
|
||||
## Options
|
||||
|
||||
- `g:quickfix_mapping_delete`: default is `dd`
|
||||
- `g:quickfix_mapping_visual_delete`: default is `d`
|
||||
- `g:quickfix_mapping_filter_filename`: default is `c`
|
||||
- `g:quickfix_mapping_rfilter_filename`: default is `C`
|
||||
- `g:quickfix_mapping_filter_text`: default is `o`
|
||||
- `g:quickfix_mapping_rfilter_text`: default is `O`
|
||||
- `g:quickfix_mapping_delete`: default is `dd`
|
||||
- `g:quickfix_mapping_visual_delete`: default is `d`
|
||||
- `g:quickfix_mapping_filter_filename`: default is `c`
|
||||
- `g:quickfix_mapping_rfilter_filename`: default is `C`
|
||||
- `g:quickfix_mapping_filter_text`: default is `o`
|
||||
- `g:quickfix_mapping_rfilter_text`: default is `O`
|
||||
- `g:quickfix_mapping_undo`: default is `u`
|
||||
|
||||
## Feedback
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
local qf_historys = {}
|
||||
|
||||
M.setup = function()
|
||||
local group = vim.api.nvim_create_augroup('quickfix_mapping', {
|
||||
clear = true,
|
||||
@ -20,7 +22,10 @@ M.setup = function()
|
||||
vim.keymap.set('n', vim.g.quickfix_mapping_delete or 'dd', function()
|
||||
local qflist = vim.fn.getqflist()
|
||||
local line = vim.fn.line('.')
|
||||
table.remove(qflist, line)
|
||||
if #qflist >= 1 then
|
||||
table.insert(qf_historys, vim.deepcopy(qflist))
|
||||
table.remove(qflist, line)
|
||||
end
|
||||
vim.fn.setqflist(qflist)
|
||||
vim.cmd(tostring(line))
|
||||
end, { buffer = ev.buf })
|
||||
@ -50,8 +55,11 @@ M.setup = function()
|
||||
if from > to then
|
||||
from, to = to, from
|
||||
end
|
||||
qflist = table_remove(qflist, from, to)
|
||||
vim.fn.setqflist(qflist)
|
||||
local qf = table_remove(qflist, from, to)
|
||||
if #qf ~= #qflist and #qflist ~= 0 then
|
||||
table.insert(qf_historys, qflist)
|
||||
end
|
||||
vim.fn.setqflist(qf)
|
||||
vim.cmd(tostring(from))
|
||||
end, { buffer = ev.buf })
|
||||
end,
|
||||
@ -64,12 +72,16 @@ M.setup = function()
|
||||
local input_pattern = vim.fn.input('filter pattern:')
|
||||
-- vim.cmd('noautocmd normal! :')
|
||||
local re = vim.regex(input_pattern)
|
||||
local qflist = vim.fn.getqflist()
|
||||
local qf = {}
|
||||
for _, item in ipairs(vim.fn.getqflist()) do
|
||||
for _, item in ipairs(qflist) do
|
||||
if not re:match_str(vim.fn.bufname(item.bufnr)) then
|
||||
table.insert(qf, item)
|
||||
end
|
||||
end
|
||||
if #qf ~= #qflist and #qflist ~= 0 then
|
||||
table.insert(qf_historys, qflist)
|
||||
end
|
||||
vim.fn.setqflist(qf)
|
||||
end, { buffer = ev.buf })
|
||||
end,
|
||||
@ -81,14 +93,17 @@ M.setup = function()
|
||||
callback = function(ev)
|
||||
vim.keymap.set('n', vim.g.quickfix_mapping_rfilter_filename or 'C', function()
|
||||
local input_pattern = vim.fn.input('filter pattern:')
|
||||
-- vim.cmd('noautocmd normal! :')
|
||||
local re = vim.regex(input_pattern)
|
||||
local qf = {}
|
||||
for _, item in ipairs(vim.fn.getqflist()) do
|
||||
local qflist = vim.fn.getqflist()
|
||||
for _, item in ipairs(qflist) do
|
||||
if re:match_str(vim.fn.bufname(item.bufnr)) then
|
||||
table.insert(qf, item)
|
||||
end
|
||||
end
|
||||
if #qf ~= #qflist and #qflist ~= 0 then
|
||||
table.insert(qf_historys, qflist)
|
||||
end
|
||||
vim.fn.setqflist(qf)
|
||||
end, { buffer = ev.buf })
|
||||
end,
|
||||
@ -102,11 +117,15 @@ M.setup = function()
|
||||
-- vim.cmd('noautocmd normal! :')
|
||||
local re = vim.regex(input_pattern)
|
||||
local qf = {}
|
||||
for _, item in ipairs(vim.fn.getqflist()) do
|
||||
local qflist = vim.fn.getqflist()
|
||||
for _, item in ipairs(qflist) do
|
||||
if not re:match_str(item.text) then
|
||||
table.insert(qf, item)
|
||||
end
|
||||
end
|
||||
if #qf ~= #qflist and #qflist ~= 0 then
|
||||
table.insert(qf_historys, qflist)
|
||||
end
|
||||
vim.fn.setqflist(qf)
|
||||
end, { buffer = ev.buf })
|
||||
end,
|
||||
@ -120,15 +139,31 @@ M.setup = function()
|
||||
-- vim.cmd('noautocmd normal! :')
|
||||
local re = vim.regex(input_pattern)
|
||||
local qf = {}
|
||||
for _, item in ipairs(vim.fn.getqflist()) do
|
||||
local qflist = vim.fn.getqflist()
|
||||
for _, item in ipairs(qflist) do
|
||||
if re:match_str(item.text) then
|
||||
table.insert(qf, item)
|
||||
end
|
||||
end
|
||||
if #qf ~= #qflist and #qflist ~= 0 then
|
||||
table.insert(qf_historys, qflist)
|
||||
end
|
||||
vim.fn.setqflist(qf)
|
||||
end, { buffer = ev.buf })
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ 'FileType' }, {
|
||||
pattern = 'qf',
|
||||
group = group,
|
||||
callback = function(ev)
|
||||
vim.keymap.set('n', vim.g.quickfix_mapping_undo or 'u', function()
|
||||
local qf = table.remove(qf_historys)
|
||||
if qf then
|
||||
vim.fn.setqflist(qf)
|
||||
end
|
||||
end, { buffer = ev.buf })
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -51,6 +51,7 @@ nerdtree 或者 vimfiler,默认为 vimfiler,由 `filemanager` 选项控制
|
||||
| `C` | remove items which filename not match input regex |
|
||||
| `o` | remove items which error description match input regex |
|
||||
| `O` | remove items which error description not match input regex |
|
||||
| `u` | undo last change |
|
||||
|
||||
也可以在启动函数里面使用如下变量修改默认的按键:
|
||||
|
||||
@ -60,4 +61,5 @@ nerdtree 或者 vimfiler,默认为 vimfiler,由 `filemanager` 选项控制
|
||||
- `g:quickfix_mapping_rfilter_filename`: default is `C`
|
||||
- `g:quickfix_mapping_filter_text`: default is `o`
|
||||
- `g:quickfix_mapping_rfilter_text`: default is `O`
|
||||
- `g:quickfix_mapping_undo`: default is `u`
|
||||
|
||||
|
@ -60,6 +60,7 @@ and which also can be change in bootstrap function.
|
||||
| `C` | remove items which filename not match input regex |
|
||||
| `o` | remove items which error description match input regex |
|
||||
| `O` | remove items which error description not match input regex |
|
||||
| `u` | undo last change |
|
||||
|
||||
Options to change these mappings:
|
||||
|
||||
@ -69,4 +70,5 @@ Options to change these mappings:
|
||||
- `g:quickfix_mapping_rfilter_filename`: default is `C`
|
||||
- `g:quickfix_mapping_filter_text`: default is `o`
|
||||
- `g:quickfix_mapping_rfilter_text`: default is `O`
|
||||
- `g:quickfix_mapping_undo`: default is `u`
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user