1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:20:04 +08:00

feat(flygrep): use ctrl-h toggle hidden files

This commit is contained in:
Eric Wong 2024-07-27 22:53:27 +08:00
parent 28c3ff6193
commit 98b6cae025
7 changed files with 117 additions and 13 deletions

View File

@ -6,6 +6,49 @@
" License: GPLv3
"=============================================================================
""
" @section flygrep, plugins-flygrep
" @parentsection plugins
" `flygrep` means `grep on the fly`, it will update the result as you type.
" Of course, it is running asynchronously. Before using this feature,
" you need to install a searching tool. flygrep supports those tools:
" `ag`, `rg`, `ack`, `pt` and `grep`, Choose one you like.
"
" checkout @section(usage-search-and-replace) for more info to use flygrep in
" SpaceVim.
"
" @subsection Key bindings In flygrep window
"
" After opening flygrep window, those key bindings can be used:
" >
" Key Bindings | Descriptions
" ------------------- | ----------------------------------
" Tab / Ctrl-j | move cursor to next item
" Shift-Tab / Ctrl-K | move cursor to previous item
" ScrollWheelDown | move cursor to next item
" ScrollWheelUp | move cursor to previous item
" Enter | open file at the cursor line
" Ctrl-t | open item in new tab
" LeftMouse | move cursor to mouse position
" 2-LeftMouse | open file at the mouse position
" Ctrl-f | start filter mode
" Ctrl-v | open item in vertical split window
" Ctrl-s | open item in split window
" Ctrl-q | apply all items into quickfix
" Ctrl-e | toggle fix-string mode
" Ctrl-h | toggle display hidden files
" Ctrl-r | read from register, need insert register name
" Left / Right | move cursor to left or right
" BackSpace | remove last character
" Ctrl-w | remove the Word before the cursor
" Ctrl-u | remove the Line before the cursor
" Ctrl-k | remove the Line after the cursor
" Ctrl-a / Home | Go to the beginning of the line
" End | Go to the end of the line
" <
" Loading SpaceVim api {{{
scriptencoding utf-8
if has('nvim-0.7.0')

View File

@ -3,8 +3,8 @@ Wang Shidong *flygrep* *FlyGrep*
==============================================================================
CONTENTS *FlyGrep-contents*
1. Introduction..............................................|FlyGrep-intro|
2. CONFIGURATION............................................|FlyGrep-config|
1. Introduction............................................... |FlyGrep-intro|
2. CONFIGURATION............................................. |FlyGrep-config|
==============================================================================
INTRODUCTION *FlyGrep-intro*

View File

@ -271,11 +271,12 @@ CONTENTS *SpaceVim-contents*
2. Symbol highlighter............... |SpaceVim-plugins-symbol-highlighter|
3. alternate................................. |SpaceVim-plugins-alternate|
4. autosave................................... |SpaceVim-plugins-autosave|
5. iedit......................................... |SpaceVim-plugins-iedit|
6. runner....................................... |SpaceVim-plugins-runner|
7. scrollbar................................. |SpaceVim-plugins-scrollbar|
8. tab manager.............................. |SpaceVim-plugins-tabmanager|
9. todo manager............................ |SpaceVim-plugins-todomanager|
5. flygrep..................................... |SpaceVim-plugins-flygrep|
6. iedit......................................... |SpaceVim-plugins-iedit|
7. runner....................................... |SpaceVim-plugins-runner|
8. scrollbar................................. |SpaceVim-plugins-scrollbar|
9. tab manager.............................. |SpaceVim-plugins-tabmanager|
10. todo manager........................... |SpaceVim-plugins-todomanager|
9. API......................................................... |SpaceVim-api|
1. clock............................................. |SpaceVim-api-clock|
2. cmdlinemenu................................. |SpaceVim-api-cmdlinemenu|
@ -7647,6 +7648,47 @@ AUTOSAVE *SpaceVim-plugins-autosave*
The `autosave` plugin will save your work automatically, and this plugin has
been used in `edit` layer, checkout |SpaceVim-layers-edit| for more info.
==============================================================================
FLYGREP *SpaceVim-plugins-flygrep*
`flygrep` means `grep on the fly`, it will update the result as you type. Of
course, it is running asynchronously. Before using this feature, you need to
install a searching tool. flygrep supports those tools: `ag`, `rg`, `ack`,
`pt` and `grep`, Choose one you like.
checkout |SpaceVim-usage-search-and-replace| for more info to use flygrep in
SpaceVim.
KEY BINDINGS IN FLYGREP WINDOW
After opening flygrep window, those key bindings can be used:
>
Key Bindings | Descriptions
------------------- | ----------------------------------
Tab / Ctrl-j | move cursor to next item
Shift-Tab / Ctrl-K | move cursor to previous item
ScrollWheelDown | move cursor to next item
ScrollWheelUp | move cursor to previous item
Enter | open file at the cursor line
Ctrl-t | open item in new tab
LeftMouse | move cursor to mouse position
2-LeftMouse | open file at the mouse position
Ctrl-f | start filter mode
Ctrl-v | open item in vertical split window
Ctrl-s | open item in split window
Ctrl-q | apply all items into quickfix
Ctrl-e | toggle fix-string mode
Ctrl-h | toggle display hidden files
Ctrl-r | read from register, need insert register name
Left / Right | move cursor to left or right
BackSpace | remove last character
Ctrl-w | remove the Word before the cursor
Ctrl-u | remove the Line before the cursor
Ctrl-k | remove the Line after the cursor
Ctrl-a / Home | Go to the beginning of the line
End | Go to the end of the line
<
==============================================================================
IEDIT *SpaceVim-plugins-iedit*

View File

@ -115,7 +115,7 @@ function M._handle_input(...)
'',
'g'
)
M._prompt.cursor_char = M.__cmp.matchstr(M._prompt.cursor_begin, '^.')
M._prompt.cursor_char = M.__cmp.fn.matchstr(M._prompt.cursor_begin, '^.')
M._prompt.cursor_begin = ''
M._build_prompt()
goto continue

View File

@ -44,7 +44,7 @@ local timer_stop = vim.fn.timer_stop
-- the script local values, same as s: in vim script
local previous_winid = -1
local grep_expr = ''
local grep_default_exe, grep_default_opt, grep_default_ropt, grep_default_expr_opt, grep_default_fix_string_opt, grep_default_ignore_case, grep_default_smart_case =
local grep_default_exe, grep_default_opt, grep_default_ropt, grep_default_expr_opt, grep_default_fix_string_opt, grep_default_ignore_case, grep_default_smart_case, grep_default_hidden_opt=
require('spacevim.plugin.search').default_tool()
local grep_timer_id = -1
@ -63,6 +63,7 @@ local grep_ropt = {}
local grep_ignore_case = {}
local grep_smart_case = {}
local grep_expr_opt = {}
local grep_hidden_opt = {}
local search_hi_id = -1
local filter_hi_id = -1
local grep_mode = 'expr'
@ -71,6 +72,7 @@ local preview_able = false
local grep_history = {}
local preview_win_id = -1
local filter_file = ''
local show_hidden_files = false
--- @return table # a list of searching pattern history
local function read_histroy()
@ -128,6 +130,9 @@ local function get_search_cmd(expr)
if vim.o.ignorecase then
append(cmd, grep_ignore_case)
end
if show_hidden_files then
append(cmd, grep_hidden_opt)
end
if vim.o.smartcase then
append(cmd, grep_smart_case)
end
@ -686,6 +691,12 @@ local function start_replace()
end
end
local function toggle_hidden_files()
show_hidden_files = not show_hidden_files
mpt._oninputpro()
mpt._handle_fly(mpt._prompt.cursor_begin .. mpt._prompt.cursor_char .. mpt._prompt.cursor_end)
end
mpt._function_key = {
[Key.t('<Tab>')] = next_item,
[Key.t('<C-j>')] = next_item,
@ -701,6 +712,7 @@ mpt._function_key = {
[Key.t('<C-v>')] = open_item_vertically,
[Key.t('<C-s>')] = open_item_horizontally,
[Key.t('<C-q>')] = apply_to_quickfix,
[Key.t('<C-h>')] = toggle_hidden_files,
[Key.t('<M-r>')] = start_replace,
[Key.t('<C-p>')] = toggle_preview,
[Key.t('<C-e>')] = toggle_expr_mode,
@ -820,6 +832,7 @@ function M.open(argv)
grep_ignore_case = argv.ignore_case or grep_default_ignore_case
grep_smart_case = argv.smart_case or grep_default_smart_case
grep_expr_opt = argv.expr_opt or grep_default_expr_opt
grep_hidden_opt = argv.hidden_opt or grep_default_hidden_opt
logger.info('FlyGrep startting ===========================')
logger.info(' executable : ' .. grep_exe)
logger.info(' option : ' .. vim.fn.string(grep_opt))

View File

@ -42,6 +42,7 @@ local function show_key(key, where)
focusable = false,
noautocmd = true,
border = 'single',
zindex = 100,
})
table.insert(winids, winid)
vim.fn.setbufvar(buf, '&number', 0)

View File

@ -16,7 +16,7 @@ search_tools.a = {}
search_tools.a.command = 'ag'
search_tools.a.default_opts =
{
'-i', '--nocolor', '--filename', '--noheading', '--column', '--hidden', '--ignore',
'-i', '--nocolor', '--filename', '--noheading', '--column', '--ignore',
'.hg', '--ignore', '.svn', '--ignore', '.git', '--ignore', '.bzr',
}
search_tools.a.recursive_opt = {}
@ -25,6 +25,7 @@ search_tools.a.fixed_string_opt = {'-F'}
search_tools.a.default_fopts = {'--nonumber'}
search_tools.a.smart_case = {'-S'}
search_tools.a.ignore_case = {'-i'}
search_tools.a.hidden_opt = {'--hidden'}
search_tools.t = {}
search_tools.t.command = 'pt'
@ -49,7 +50,7 @@ search_tools.h.ignore_case = {}
search_tools.r = {}
search_tools.r.command = 'rg'
search_tools.r.default_opts = {
'--hidden', '--no-heading', '--color=never', '--with-filename', '--line-number', '--column',
'--no-heading', '--color=never', '--with-filename', '--line-number', '--column',
'-g', '!.git'
}
search_tools.r.recursive_opt = {}
@ -58,6 +59,7 @@ search_tools.r.fixed_string_opt = {'-F'}
search_tools.r.default_fopts = {'-N'}
search_tools.r.smart_case = {'-S'}
search_tools.r.ignore_case = {'-i'}
search_tools.r.hidden_opt = {'--hidden'}
search_tools.k = {}
search_tools.k.command = 'ack'
@ -106,6 +108,7 @@ search_tools.i.ignore_case = {'/I'}
--- @return table fixed_string_opt fixed string option of searching tool
--- @return table ignore_case ignore case option
--- @return table smart_case smart case option
--- @return table hidden_opt opt to show hidden files
function M.default_tool()
if search_tools.default_exe == nil then
for _, t in ipairs(vim.g.spacevim_search_tools or {'rg', 'ag', 'pt', 'ack', 'grep'}) do
@ -118,11 +121,12 @@ function M.default_tool()
search_tools.fixed_string_opt = search_tools[key]['fixed_string_opt']
search_tools.ignore_case = search_tools[key]['ignore_case']
search_tools.smart_case = search_tools[key]['smart_case']
search_tools.hidden_opt = search_tools[key]['hidden_opt']
break
end
end
if search_tools.default_exe == nil then
return '', {}, {}, {}, {}, {}, {}
return '', {}, {}, {}, {}, {}, {}, {}
end
end
return search_tools.default_exe,
@ -131,7 +135,8 @@ function M.default_tool()
search_tools.expr_opt,
search_tools.fixed_string_opt,
search_tools.ignore_case,
search_tools.smart_case
search_tools.smart_case,
search_tools.hidden_opt
end