diff --git a/autoload/SpaceVim.vim b/autoload/SpaceVim.vim index 6b8f16cc9..313c26678 100644 --- a/autoload/SpaceVim.vim +++ b/autoload/SpaceVim.vim @@ -630,6 +630,10 @@ let g:spacevim_project_rooter_patterns = ['.git/', '_darcs/', '.hg/', '.bzr/', ' " Enable/Disable changing directory automatically. Enabled by default. let g:spacevim_project_rooter_automatically = 1 +"" +" Config the command line prompt for flygrep and denite etc. +let g:spacevim_commandline_prompt = '➭' + "" " @section lint_on_the_fly, options-lint_on_the_fly " @parentsection options diff --git a/autoload/SpaceVim/api/data/string.vim b/autoload/SpaceVim/api/data/string.vim index 815543963..927189ec3 100644 --- a/autoload/SpaceVim/api/data/string.vim +++ b/autoload/SpaceVim/api/data/string.vim @@ -7,6 +7,16 @@ " License: GPLv3 "============================================================================= +"" +" @section data#string, api-data-string +" @parentsection api +" +" @subsection Functions +" +" split(str [, sep [, keepempty[, max]]]) +" +" run vim command, and return the output of such command. + let s:self = {} function! s:self.trim(str) abort @@ -125,6 +135,28 @@ function! s:self.strB2Q(str) abort endfunction + +function! s:self.split(str, ...) abort + let sep = get(a:000, 0, '') + let keepempty = get(a:000, 1, 0) + let max = get(a:000, 2, -1) + let rlist = split(a:str, sep, keepempty) + if max >= 2 + let rst = [] + for item in rlist + if len(rst) >= max - 1 + break + endif + call add(rst, item) + endfor + let last = join(rlist[max-1:], sep) + call add(rst, last) + return rst + else + return rlist + endif +endfunction + function! SpaceVim#api#data#string#get() abort return deepcopy(s:self) endfunction diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim index d55aada36..2aa3953c3 100644 --- a/autoload/SpaceVim/api/prompt.vim +++ b/autoload/SpaceVim/api/prompt.vim @@ -141,7 +141,7 @@ endf func! s:self._build_prompt() abort normal! : - let ident = repeat(' ', self.__cmp.win_screenpos(0)[1]) + let ident = repeat(' ', self.__cmp.win_screenpos(0)[1] - 1) echohl Comment | echon ident . self._prompt.mpt echohl None | echon self._prompt.begin echohl Wildmenu | echon self._prompt.cursor diff --git a/autoload/SpaceVim/api/vim/compatible.vim b/autoload/SpaceVim/api/vim/compatible.vim index eae36a0e2..c0268d5e7 100644 --- a/autoload/SpaceVim/api/vim/compatible.vim +++ b/autoload/SpaceVim/api/vim/compatible.vim @@ -27,6 +27,15 @@ " has(feature) " " check if {feature} is supported in current version. +" +" getjumplist() +" +" return a list of jump position, like result of |:jump| + + +" Load SpaceVim API: + +let s:STRING = SpaceVim#api#import('data#string') let s:self = {} @@ -249,9 +258,31 @@ else endif function! s:self.set_buf_line() abort - + endfunction +if exists('*getjumplist') + function! s:self.getjumplist() abort + return getjumplist() + endfunction +else + function! s:self.getjumplist() abort + let jumpinfo = split(self.execute(':jumps'), "\n")[1:-2] + let result = [] + " 20 281 23 -invalid- + for info in jumpinfo + let [jump, line, col, file_text] = s:STRING.split(info, '', 0, 4) + call add(result, { + \ 'bufnr' : jump, + \ 'lnum' : line, + \ 'col' : col, + \ }) + endfor + return result + endfunction +endif + + function! SpaceVim#api#vim#compatible#get() abort return deepcopy(s:self) endfunction diff --git a/autoload/SpaceVim/mapping/search.vim b/autoload/SpaceVim/mapping/search.vim index ee5b93f3a..84f12eb9c 100644 --- a/autoload/SpaceVim/mapping/search.vim +++ b/autoload/SpaceVim/mapping/search.vim @@ -24,7 +24,7 @@ let s:search_tools.a = {} let s:search_tools.a.command = 'ag' let s:search_tools.a.default_opts = \ [ - \ '-i', '--column', '--hidden', '--ignore', + \ '-i', '--nocolor', '--filename', '--noheading', '--column', '--hidden', '--ignore', \ '.hg', '--ignore', '.svn', '--ignore', '.git', '--ignore', '.bzr', \ ] let s:search_tools.a.recursive_opt = [] diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 3e46abf0d..cbd32b18b 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -43,6 +43,7 @@ function! s:grep_timer(timer) abort endif let cmd = s:get_search_cmd(s:current_grep_pattern) call SpaceVim#logger#info('grep cmd: ' . string(cmd)) + call SpaceVim#logger#info('full cmd: ' . join(cmd)) let s:grepid = s:JOB.start(cmd, { \ 'on_stdout' : function('s:grep_stdout'), \ 'on_stderr' : function('s:grep_stderr'), @@ -64,17 +65,28 @@ function! s:get_search_cmd(expr) abort endif let cmd += s:grep_expr_opt if !empty(s:grep_files) && type(s:grep_files) == 3 + " grep files is a list, which mean to use flygrep searching in + " multiple files let cmd += [a:expr] + s:grep_files elseif !empty(s:grep_files) && type(s:grep_files) == 1 + " grep file is a single file let cmd += [a:expr] + [s:grep_files] elseif !empty(s:grep_dir) + " grep dir is not a empty string if s:grep_exe == 'findstr' let cmd += [s:grep_dir] + [a:expr] + ['%CD%\*'] else let cmd += [a:expr] + [s:grep_dir] endif else - let cmd += [a:expr] + s:grep_ropt + " if grep dir is empty, grep files is empty, which means searhing in + " current directory. + let cmd += [a:expr] + " in window, when using rg, ag, need to add '.' at the end. + if s:SYS.isWindows && (s:grep_exe == 'rg' || s:grep_exe == 'ag' ) + let cmd += ['.'] + endif + let cmd += s:grep_ropt endif " let cmd = map(cmd, 'shellescape(v:val)') " if has('win32') @@ -211,7 +223,7 @@ endfunction " }}} " API: MPT._prompt {{{ -let s:MPT._prompt.mpt = '➭ ' +let s:MPT._prompt.mpt = g:spacevim_commandline_prompt . ' ' " }}} " API: MPT._onclose {{{ @@ -250,6 +262,8 @@ function! s:grep_stdout(id, data, event) abort let datas =filter(a:data, '!empty(v:val)') " let datas = s:LIST.uniq_by_func(datas, function('s:file_line')) if bufnr('%') == s:flygrep_buffer_id + " You probably split lines by \n, but Windows ses \r\n, so the \r (displayed via ^M) is still left. + " ag support is broken in windows + neovim-qt if getline(1) ==# '' call setline(1, datas) else diff --git a/config/plugins/denite.vim b/config/plugins/denite.vim index 926ab0101..998e43f3d 100644 --- a/config/plugins/denite.vim +++ b/config/plugins/denite.vim @@ -13,7 +13,7 @@ let s:denite_options = { \ 'highlight_matched_range' : 'MoreMsg', \ 'direction': 'rightbelow', \ 'statusline' : has('patch-7.4.1154') ? v:false : 0, - \ 'prompt' : '➭', + \ 'prompt' : g:spacevim_commandline_prompt, \ }} function! s:profile(opts) abort diff --git a/docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md b/docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md index c4cab9b31..d8c13f309 100644 --- a/docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md +++ b/docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md @@ -20,6 +20,18 @@ SpaceVim 中代码检索采用的是 FlyGrep 这个插件,包括了常用的 ![searching project](https://user-images.githubusercontent.com/13142418/35278709-7856ed62-0010-11e8-8b1e-e6cc6374b0dc.gif) +## 安装搜索工具 + +FlyGrep 异步调用搜索工具,搜索并展示结果,目前支持的搜索工具包括:`rg`, `ag`, `pt`, `grep`, `findstr`, `ack`。 +以上这些工具在 Linux 系统下默认包含了 `grep`,Windows 系统下默认包含了 `findstr`。其他工具安装方式如下: + +### Windows + +在 Windows 下,可以直接下载解压,可执行文件所在目录加入 `PATH` 即可。 + +- rg: [ripgrep releases](https://github.com/BurntSushi/ripgrep/releases) +- ag: [the_silver_searcher-win32](https://github.com/k-takata/the_silver_searcher-win32/releases) + ## 特性 - 实时检索全工程文件 diff --git a/test/api/data/string.vader b/test/api/data/string.vader index 868c01201..2134c404c 100644 --- a/test/api/data/string.vader +++ b/test/api/data/string.vader @@ -1,5 +1,6 @@ Execute ( SpaceVim api: data#string ): let str = SpaceVim#api#import('data#string') + AssertEqual str.split(' 20 281 23 -invalid-', '', 0, 4)[2], '23' AssertEqual str.trim(' s b '), 's b' AssertEqual str.trim_start(' s b '), 's b ' AssertEqual str.trim_end(' s b '), ' s b' diff --git a/wiki/cn/Following-HEAD.md b/wiki/cn/Following-HEAD.md index 31e928408..e4351e9e7 100644 --- a/wiki/cn/Following-HEAD.md +++ b/wiki/cn/Following-HEAD.md @@ -45,7 +45,7 @@ - Fix FlyGrep syntax to support different outputs ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2363), [`0b26f40`](https://github.com/SpaceVim/SpaceVim/commit/0b26f407d879427505418f5c3b4c1d753f3f4317)) - Fix `project_rooter_automatically = 0` option to not change directory to project root ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2365)) - Add log for generate configuration file ([#2369](https://github.com/SpaceVim/SpaceVim/pull/2369)) - +- Fix flygrep and neovim support in windows os ([#2371](https://github.com/SpaceVim/SpaceVim/pull/2371)) ### 移除的功能 @@ -57,7 +57,6 @@ ## 上一个版本 -SpaceVim 于 2018-09-26 发布 v0.9.0 版本,可查阅办法发布文章: +SpaceVim 于 2018-09-26 发布 v0.9.0 版本,可查阅版本发布文章: - [SpaceVim 发布 v0.9.0 版本](https://spacevim.org/SpaceVim-release-v0.9.0/) - diff --git a/wiki/en/Following-HEAD.md b/wiki/en/Following-HEAD.md index 5c9ec58af..f228a29df 100644 --- a/wiki/en/Following-HEAD.md +++ b/wiki/en/Following-HEAD.md @@ -41,9 +41,11 @@ The next release is v1.0.0. - Fix dein-ui error, add syntax ([#2352](https://github.com/SpaceVim/SpaceVim/pull/2352), [`c9e1d4c`](https://github.com/SpaceVim/SpaceVim/commit/c9e1d4c9635c483bb3334c00ed36026d18950070)) - Fix fullscreen key binding ([#2351](https://github.com/SpaceVim/SpaceVim/pull/2351)) - Added missed syntax for detached FlyGrep ([#2353](https://github.com/SpaceVim/SpaceVim/pull/2353), [`08d0713`](https://github.com/SpaceVim/SpaceVim/commit/08d0713c4494ca401942a6ca10a48a1ac8484ce1)) +- Add log for generate configuration file ([#2369](https://github.com/SpaceVim/SpaceVim/pull/2369)) - Fix FlyGrep syntax to support different outputs ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2363), [`0b26f40`](https://github.com/SpaceVim/SpaceVim/commit/0b26f407d879427505418f5c3b4c1d753f3f4317)) - Fix `project_rooter_automatically = 0` option to not change directory to project root ([#2363](https://github.com/SpaceVim/SpaceVim/pull/2365)) - Add log for generate configuration file ([#2369](https://github.com/SpaceVim/SpaceVim/pull/2369)) +- Fix flygrep and neovim support in windows os ([#2371](https://github.com/SpaceVim/SpaceVim/pull/2371)) ### Removed @@ -55,5 +57,6 @@ The next release is v1.0.0. ## Latest Release -SpaceVim releases v0.9.0 at 2018-09-26, please check the -[release page](https://spacevim.org/SpaceVim-release-v0.9.0/) for all the details +SpaceVim releases v0.9.0 at 2018-09-26, please check the release page: + +- [SpaceVim releases v0.9.0](https://spacevim.org/SpaceVim-release-v0.9.0/) for all the details