1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 00:10:07 +08:00

Add file search option (#4245)

This commit is contained in:
Wang Shidong 2021-05-01 22:47:19 +08:00 committed by GitHub
parent 64b9909276
commit 2dd0f66ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 44 deletions

View File

@ -173,6 +173,18 @@ let g:spacevim_enable_guicolors = 0
" < " <
let g:spacevim_escape_key_binding = 'jk' let g:spacevim_escape_key_binding = 'jk'
""
" @section file_searching_tools, options-file_searching_tools
" @parentsection options
" Set the default file searching tool used by `SPC f /`, by default it is `[]`.
" The first item in this list is the name of the tool, the second one is the
" default command. for example:
" >
" file_searching_tools = ['find', 'find -not -iwholename "*.git*" ']
" <
let g:spacevim_file_searching_tools = []
"" ""
" @section enable_googlesuggest, options-enable_googlesuggest " @section enable_googlesuggest, options-enable_googlesuggest
" @parentsection options " @parentsection options

View File

@ -17,13 +17,17 @@ let s:FILE = SpaceVim#api#import('file')
"}}} "}}}
let s:support_tools = ['find', 'fd'] let s:file_searching_commands = {
let s:default_cmd = {
\ 'find' : 'find -not -iwholename "*.git*" ', \ 'find' : 'find -not -iwholename "*.git*" ',
\ 'fd' : 'fd', \ 'fd' : 'fd',
\ } \ }
let s:current_tool = 'find' if !empty(g:spacevim_file_searching_tools)
let s:MPT._prompt.mpt = ' ' . s:default_cmd[s:current_tool] . ' ' call extend(s:file_searching_commands, {g:spacevim_file_searching_tools[0] : g:spacevim_file_searching_tools[1]})
let s:current_tool = g:spacevim_file_searching_tools[0]
else
let s:current_tool = 'find'
endif
let s:MPT._prompt.mpt = ' ' . s:file_searching_commands[s:current_tool] . ' '
let s:options = {} let s:options = {}
let s:second_option = {} let s:second_option = {}
let s:options.find = { let s:options.find = {
@ -119,11 +123,7 @@ let s:second_option.fd = {
\ } \ }
function! s:start_find() abort function! s:start_find() abort
if s:current_tool ==# 'find' let cmd = s:file_searching_commands[s:current_tool] . ' ' . s:MPT._prompt.begin . s:MPT._prompt.cursor . s:MPT._prompt.end
let cmd = s:default_cmd[s:current_tool] . ' ' . s:MPT._prompt.begin . s:MPT._prompt.cursor . s:MPT._prompt.end
elseif s:current_tool ==# 'fd'
let cmd = s:default_cmd[s:current_tool] . ' ' . s:MPT._prompt.begin . s:MPT._prompt.cursor . s:MPT._prompt.end
endif
let s:MPT._quit = 1 let s:MPT._quit = 1
call s:MPT._clear_prompt() call s:MPT._clear_prompt()
call s:close_buffer() call s:close_buffer()
@ -210,7 +210,7 @@ function! s:switch_tool() abort
let s:MPT._prompt.begin = '' let s:MPT._prompt.begin = ''
let s:MPT._prompt.cursor = '' let s:MPT._prompt.cursor = ''
let s:MPT._prompt.end = '' let s:MPT._prompt.end = ''
let s:MPT._prompt.mpt = ' ' . s:default_cmd[s:current_tool] . ' ' let s:MPT._prompt.mpt = ' ' . s:file_searching_commands[s:current_tool] . ' '
redraw redraw
call s:MPT._build_prompt() call s:MPT._build_prompt()
endfunction endfunction
@ -227,13 +227,16 @@ function! s:handle_command_line(cmd) abort
return return
endif endif
let argv = split(s:MPT._prompt.begin)[-1] let argv = split(s:MPT._prompt.begin)[-1]
if s:MPT._prompt.begin[-1:] ==# ' ' && has_key(s:second_option[s:current_tool], argv) if s:MPT._prompt.begin[-1:] ==# ' '
\ && has_key(s:second_option, s:current_tool)
\ && has_key(s:second_option[s:current_tool], argv)
let line = [] let line = []
for item in items(s:second_option[s:current_tool][argv]) for item in items(s:second_option[s:current_tool][argv])
call add(line, ' ' . item[0] . repeat(' ', 8 - len(item[0])) . item[1]) call add(line, ' ' . item[0] . repeat(' ', 8 - len(item[0])) . item[1])
endfor endfor
call setline(1, line) call setline(1, line)
elseif argv =~# '^-[a-zA-Z0-1]*' elseif argv =~# '^-[a-zA-Z0-1]*'
\ && has_key(s:options, s:current_tool)
let argvs = filter(deepcopy(s:options[s:current_tool]), 'v:key =~ argv') let argvs = filter(deepcopy(s:options[s:current_tool]), 'v:key =~ argv')
let line = [] let line = []
for item in items(argvs) for item in items(argvs)

View File

@ -43,41 +43,42 @@ CONTENTS *SpaceVim-contents*
23. enable_ycm.............................|SpaceVim-options-enable_ycm| 23. enable_ycm.............................|SpaceVim-options-enable_ycm|
24. error_symbol.........................|SpaceVim-options-error_symbol| 24. error_symbol.........................|SpaceVim-options-error_symbol|
25. escape_key_binding.............|SpaceVim-options-escape_key_binding| 25. escape_key_binding.............|SpaceVim-options-escape_key_binding|
26. filemanager...........................|SpaceVim-options-filemanager| 26. file_searching_tools.........|SpaceVim-options-file_searching_tools|
27. filetree_direction.............|SpaceVim-options-filetree_direction| 27. filemanager...........................|SpaceVim-options-filemanager|
28. guifont...................................|SpaceVim-options-guifont| 28. filetree_direction.............|SpaceVim-options-filetree_direction|
29. home_files_number...............|SpaceVim-options-home_files_number| 29. guifont...................................|SpaceVim-options-guifont|
30. info_symbol...........................|SpaceVim-options-info_symbol| 30. home_files_number...............|SpaceVim-options-home_files_number|
31. keep_server_alive...............|SpaceVim-options-keep_server_alive| 31. info_symbol...........................|SpaceVim-options-info_symbol|
32. language.................................|SpaceVim-options-language| 32. keep_server_alive...............|SpaceVim-options-keep_server_alive|
33. lint_engine...........................|SpaceVim-options-lint_engine| 33. language.................................|SpaceVim-options-language|
34. lint_on_the_fly...................|SpaceVim-options-lint_on_the_fly| 34. lint_engine...........................|SpaceVim-options-lint_engine|
35. max_column.............................|SpaceVim-options-max_column| 35. lint_on_the_fly...................|SpaceVim-options-lint_on_the_fly|
36. plugin_bundle_dir...............|SpaceVim-options-plugin_bundle_dir| 36. max_column.............................|SpaceVim-options-max_column|
37. plugin_manager_processes.|SpaceVim-options-plugin_manager_processes| 37. plugin_bundle_dir...............|SpaceVim-options-plugin_bundle_dir|
38. project_rooter_automatically 38. plugin_manager_processes.|SpaceVim-options-plugin_manager_processes|
39. project_rooter_automatically
...............................|SpaceVim-options-project_rooter_automatically| ...............................|SpaceVim-options-project_rooter_automatically|
39. project_rooter_outermost.|SpaceVim-options-project_rooter_outermost| 40. project_rooter_outermost.|SpaceVim-options-project_rooter_outermost|
40. project_rooter_patterns...|SpaceVim-options-project_rooter_patterns| 41. project_rooter_patterns...|SpaceVim-options-project_rooter_patterns|
41. projects_cache_num.............|SpaceVim-options-projects_cache_num| 42. projects_cache_num.............|SpaceVim-options-projects_cache_num|
42. realtime_leader_guide.......|SpaceVim-options-realtime_leader_guide| 43. realtime_leader_guide.......|SpaceVim-options-realtime_leader_guide|
43. relativenumber.....................|SpaceVim-options-relativenumber| 44. relativenumber.....................|SpaceVim-options-relativenumber|
44. retry_cnt...............................|SpaceVim-options-retry_cnt| 45. retry_cnt...............................|SpaceVim-options-retry_cnt|
45. search_tools.........................|SpaceVim-options-search_tools| 46. search_tools.........................|SpaceVim-options-search_tools|
46. sidebar_width.......................|SpaceVim-options-sidebar_width| 47. sidebar_width.......................|SpaceVim-options-sidebar_width|
47. snippet_engine.....................|SpaceVim-options-snippet_engine| 48. snippet_engine.....................|SpaceVim-options-snippet_engine|
48. statusline_iseparator.......|SpaceVim-options-statusline_iseparator| 49. statusline_iseparator.......|SpaceVim-options-statusline_iseparator|
49. statusline_left_sections.|SpaceVim-options-statusline_left_sections| 50. statusline_left_sections.|SpaceVim-options-statusline_left_sections|
50. statusline_separator.........|SpaceVim-options-statusline_separator| 51. statusline_separator.........|SpaceVim-options-statusline_separator|
51. statusline_unicode_symbols 52. statusline_unicode_symbols
.................................|SpaceVim-options-statusline_unicode_symbols| .................................|SpaceVim-options-statusline_unicode_symbols|
52. terminal_cursor_shape.......|SpaceVim-options-terminal_cursor_shape| 53. terminal_cursor_shape.......|SpaceVim-options-terminal_cursor_shape|
53. vim_help_language...............|SpaceVim-options-vim_help_language| 54. vim_help_language...............|SpaceVim-options-vim_help_language|
54. vimcompatible.......................|SpaceVim-options-vimcompatible| 55. vimcompatible.......................|SpaceVim-options-vimcompatible|
55. warning_symbol.....................|SpaceVim-options-warning_symbol| 56. warning_symbol.....................|SpaceVim-options-warning_symbol|
56. windows_index_type.............|SpaceVim-options-windows_index_type| 57. windows_index_type.............|SpaceVim-options-windows_index_type|
57. windows_leader.....................|SpaceVim-options-windows_leader| 58. windows_leader.....................|SpaceVim-options-windows_leader|
58. windows_smartclose.............|SpaceVim-options-windows_smartclose| 59. windows_smartclose.............|SpaceVim-options-windows_smartclose|
3. Configuration...........................................|SpaceVim-config| 3. Configuration...........................................|SpaceVim-config|
4. Commands..............................................|SpaceVim-commands| 4. Commands..............................................|SpaceVim-commands|
5. Functions............................................|SpaceVim-functions| 5. Functions............................................|SpaceVim-functions|
@ -440,6 +441,16 @@ to disable this key binding, set this option to empty string.
escape_key_binding = 'jk' escape_key_binding = 'jk'
< <
==============================================================================
FILE_SEARCHING_TOOLS *SpaceVim-options-file_searching_tools*
Set the default file searching tool used by `SPC f /`, by default it is `[]`.
The first item in this list is the name of the tool, the second one is the
default command. for example:
>
file_searching_tools = ['find', 'find -not -iwholename "*.git*" ']
<
============================================================================== ==============================================================================
FILEMANAGER *SpaceVim-options-filemanager* FILEMANAGER *SpaceVim-options-filemanager*

View File

@ -1409,6 +1409,17 @@ By default, `find` is the default tool, you can use `ctrl-e` to switch tools.
![find](https://user-images.githubusercontent.com/13142418/97999590-79717000-1e26-11eb-91b1-458ab30d6254.gif) ![find](https://user-images.githubusercontent.com/13142418/97999590-79717000-1e26-11eb-91b1-458ab30d6254.gif)
To change the default file searching tool, you can use `file_searching_tools` option.
It is `[]` by default.
```toml
[options]
file_searching_tools = ['find', 'find -not -iwholename "*.git*" ']
```
The first item is the name of the tool, the second one is the default searching command.
#### Vim and SpaceVim files #### Vim and SpaceVim files
Convenient key bindings are located under the prefix `SPC f v` to quickly navigate between Vim and SpaceVim specific files. Convenient key bindings are located under the prefix `SPC f v` to quickly navigate between Vim and SpaceVim specific files.