mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 07:09:11 +08:00
Add function for config searching tool (#2235)
This commit is contained in:
parent
00c5192eac
commit
540b556d19
@ -201,3 +201,76 @@ function! SpaceVim#mapping#search#getFopt(exe) abort
|
||||
let key = s:search_tools.namespace[a:exe]
|
||||
return s:search_tools[key]['default_fopts']
|
||||
endfunction
|
||||
|
||||
|
||||
" the profile of a search tool should be:
|
||||
" { 'ag' : {
|
||||
" 'namespace' : '', " a single char a-z
|
||||
" 'command' : '', " executable
|
||||
" 'default_opts' : [], " default options
|
||||
" 'recursive_opt' : [], " default recursive options
|
||||
" 'expr_opt' : '', " option for enable expr mode
|
||||
" 'fixed_string_opt' : '', " option for enable fixed string mode
|
||||
" 'ignore_case' : '', " option for enable ignore case mode
|
||||
" 'smart_case' : '', " option for enable smart case mode
|
||||
" }
|
||||
" }
|
||||
"
|
||||
" so the finale command line is :
|
||||
" [command]
|
||||
" + [ignore_case_opt]?
|
||||
" + [smart_case_opt]?
|
||||
" + [string_opt]/[expr_opt]?
|
||||
" + {expr}
|
||||
" + {files or dir}
|
||||
" + [roptions]
|
||||
function! SpaceVim#mapping#search#profile(opt) abort
|
||||
|
||||
for key in keys(a:opt)
|
||||
if has_key(s:search_tools.namespace, key)
|
||||
for opt_key in keys(s:search_tools[s:search_tools.namespace[key]])
|
||||
if has_key(a:opt[key], opt_key)
|
||||
let s:search_tools[s:search_tools.namespace[key]][opt_key] = a:opt[key][opt_key]
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call s:add_new_search_tool(a:opt[key])
|
||||
endif
|
||||
endfor
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#mapping#search#getprofile(...) abort
|
||||
|
||||
if a:0 > 0
|
||||
let tool = get(s:search_tools.namespace, a:1, '')
|
||||
if !empty(tool)
|
||||
return deepcopy(s:search_tools[tool])
|
||||
endif
|
||||
else
|
||||
if !has_key(s:search_tools, 'default_exe')
|
||||
for t in get(g:, 'spacevim_search_tools', ['rg', 'ag', 'pt', 'ack', 'grep'])
|
||||
if executable(t)
|
||||
let s:search_tools.default_exe = t
|
||||
let key = s:search_tools.namespace[t]
|
||||
let s:search_tools.default_opt = s:search_tools[key]['default_opts']
|
||||
let s:search_tools.default_ropt = s:search_tools[key]['recursive_opt']
|
||||
let s:search_tools.expr_opt = s:search_tools[key]['expr_opt']
|
||||
let s:search_tools.fixed_string_opt = s:search_tools[key]['fixed_string_opt']
|
||||
let s:search_tools.ignore_case = s:search_tools[key]['ignore_case']
|
||||
let s:search_tools.smart_case = s:search_tools[key]['smart_case']
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if has_key(s:search_tools, 'default_exe')
|
||||
return deepcopy(s:search_tools[s:search_tools.namespace[s:search_tools.default_exe]])
|
||||
endif
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:add_new_search_tool(tool) abort
|
||||
" TODO: add new tools,
|
||||
" 1. we should check namespace
|
||||
endfunction
|
||||
|
@ -64,6 +64,7 @@ lang: cn
|
||||
- [以 `z` 开头的命令](#以-z-开头的命令)
|
||||
- [搜索](#搜索)
|
||||
- [使用额外工具](#使用额外工具)
|
||||
- [配置搜索工具](#配置搜索工具)
|
||||
- [常用按键绑定](#常用按键绑定)
|
||||
- [在当前文件中进行搜索](#在当前文件中进行搜索)
|
||||
- [搜索当前文件所在的文件夹](#搜索当前文件所在的文件夹)
|
||||
@ -1291,6 +1292,36 @@ Notes:
|
||||
**注意** 如果你使用 `pt`, [TCL parser tools](https://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/apps/pt.html)
|
||||
同时也需要安装一个名叫 `pt` 的命令行工具.
|
||||
|
||||
##### 配置搜索工具
|
||||
|
||||
若需要修改默认搜索工具的选项,可以使用启动函数,在启动函数中配置各种搜索工具的默认选项。
|
||||
下面是一个修改 `rg` 默认搜索选项的配置示例:
|
||||
|
||||
```vim
|
||||
function! myspacevim#before() abort
|
||||
let profile = SpaceVim#mapping#search#getprofile('rg')
|
||||
let default_opt = profile.default_opts + ['--no-ignore-vcs']
|
||||
call SpaceVim#mapping#search#profile({'rg' : {'default_opts' : default_opt}})
|
||||
endfunction
|
||||
```
|
||||
|
||||
搜索工具配置结构为:
|
||||
|
||||
```vim
|
||||
" { 'ag' : {
|
||||
" 'namespace' : '', " a single char a-z
|
||||
" 'command' : '', " executable
|
||||
" 'default_opts' : [], " default options
|
||||
" 'recursive_opt' : [], " default recursive options
|
||||
" 'expr_opt' : '', " option for enable expr mode
|
||||
" 'fixed_string_opt' : '', " option for enable fixed string mode
|
||||
" 'ignore_case' : '', " option for enable ignore case mode
|
||||
" 'smart_case' : '', " option for enable smart case mode
|
||||
" }
|
||||
" }
|
||||
```
|
||||
|
||||
|
||||
##### 常用按键绑定
|
||||
|
||||
| Key Binding | Description |
|
||||
|
@ -62,6 +62,7 @@ description: "General documentation about how to using SpaceVim, including the q
|
||||
- [Commands starting with `z`](#commands-starting-with-z)
|
||||
- [Searching](#searching)
|
||||
- [With an external tool](#with-an-external-tool)
|
||||
- [Custom searching tool](#custom-searching-tool)
|
||||
- [Useful key bindings](#useful-key-bindings)
|
||||
- [Searching in current file](#searching-in-current-file)
|
||||
- [Searching in buffer directory](#searching-in-buffer-directory)
|
||||
@ -1334,6 +1335,37 @@ Notes:
|
||||
|
||||
**Beware** if you use `pt`, [TCL parser tools](https://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/apps/pt.html) also install a command line tool called `pt`.
|
||||
|
||||
|
||||
##### Custom searching tool
|
||||
|
||||
to change the option of a search tool, you need to use bootstrap function. here is an example
|
||||
how to change the default option of searching tool `rg`.
|
||||
|
||||
```vim
|
||||
function! myspacevim#before() abort
|
||||
let profile = SpaceVim#mapping#search#getprofile('rg')
|
||||
let default_opt = profile.default_opts + ['--no-ignore-vcs']
|
||||
call SpaceVim#mapping#search#profile({'rg' : {'default_opts' : default_opt}})
|
||||
endfunction
|
||||
```
|
||||
|
||||
The structure of searching tool profile is:
|
||||
|
||||
```vim
|
||||
" { 'ag' : {
|
||||
" 'namespace' : '', " a single char a-z
|
||||
" 'command' : '', " executable
|
||||
" 'default_opts' : [], " default options
|
||||
" 'recursive_opt' : [], " default recursive options
|
||||
" 'expr_opt' : '', " option for enable expr mode
|
||||
" 'fixed_string_opt' : '', " option for enable fixed string mode
|
||||
" 'ignore_case' : '', " option for enable ignore case mode
|
||||
" 'smart_case' : '', " option for enable smart case mode
|
||||
" }
|
||||
" }
|
||||
```
|
||||
|
||||
|
||||
##### Useful key bindings
|
||||
|
||||
| Key Binding | Description |
|
||||
|
Loading…
x
Reference in New Issue
Block a user