mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-12 17:55:41 +08:00
Add quickfix support for flygrep (#3872)
This commit is contained in:
parent
b577fa2747
commit
acdcfa5aae
@ -280,6 +280,30 @@ function! s:self.add_highlight(bufnr, hl, line, col, long) abort
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:self.buf_get_lines(bufnr, start, end, strict_indexing) abort
|
||||
if exists('*nvim_buf_get_lines')
|
||||
return nvim_buf_get_lines(a:bufnr, a:start, a:end, a:strict_indexing)
|
||||
elseif exists('*getbufline') && exists('*bufload') && exists('*bufloaded')
|
||||
let lct = self.line_count(a:bufnr)
|
||||
if a:start > lct
|
||||
return
|
||||
elseif a:start >= 0 && a:end > a:start
|
||||
" in vim, getbufline will not load buffer automatically
|
||||
" but in neovim, nvim_buf_set_lines will do it.
|
||||
" @fixme vim issue #5044
|
||||
" https://github.com/vim/vim/issues/5044
|
||||
if !bufloaded(a:bufnr)
|
||||
call bufload(a:bufnr)
|
||||
endif
|
||||
return getbufline(a:bufnr, a:start + 1, a:end + 1)
|
||||
elseif a:start >= 0 && a:end < 0 && lct + a:end >= a:start
|
||||
return self.buf_get_lines(a:bufnr, a:start, lct + a:end + 1, a:strict_indexing)
|
||||
elseif a:start <= 0 && a:end > a:start && a:end < 0 && lct + a:start >= 0
|
||||
return self.buf_get_lines(a:bufnr, lct + a:start + 1, lct + a:end + 2, a:strict_indexing)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
fu! SpaceVim#api#vim#buffer#get() abort
|
||||
return deepcopy(s:self)
|
||||
|
@ -578,6 +578,30 @@ function! s:open_item_horizontally() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:apply_to_quickfix() abort
|
||||
let s:MPT._handle_fly = function('s:flygrep')
|
||||
if getline('.') !=# ''
|
||||
if s:grepid != 0
|
||||
call s:JOB.stop(s:grepid)
|
||||
endif
|
||||
let s:MPT._quit = 1
|
||||
if s:preview_able == 1
|
||||
call s:close_preview_win()
|
||||
endif
|
||||
let s:preview_able = 0
|
||||
let searching_result = s:BUFFER.buf_get_lines(s:buffer_id, 0, -1, 0)
|
||||
noautocmd q
|
||||
call s:update_history()
|
||||
if !empty(searching_result)
|
||||
cgetexpr join(searching_result, "\n")
|
||||
call setqflist([], 'a', {'title' : 'FlyGrep partten:' . s:MPT._prompt.begin . s:MPT._prompt.cursor .s:MPT._prompt.end})
|
||||
call s:MPT._clear_prompt()
|
||||
copen
|
||||
endif
|
||||
noautocmd normal! :
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:double_click() abort
|
||||
if line('.') !=# ''
|
||||
if s:grepid != 0
|
||||
@ -764,6 +788,7 @@ let s:MPT._function_key = {
|
||||
\ "\<C-f>" : function('s:start_filter'),
|
||||
\ "\<C-v>" : function('s:open_item_vertically'),
|
||||
\ "\<C-s>" : function('s:open_item_horizontally'),
|
||||
\ "\<C-q>" : function('s:apply_to_quickfix'),
|
||||
\ "\<M-r>" : function('s:start_replace'),
|
||||
\ "\<C-p>" : function('s:toggle_preview'),
|
||||
\ "\<C-e>" : function('s:toggle_expr_mode'),
|
||||
|
@ -82,18 +82,19 @@ The available scopes and corresponding keys are:
|
||||
|
||||
**Within FlyGrep buffer:**
|
||||
|
||||
| Key Bindings | Descriptions |
|
||||
| ----------------- | --------------------------------- |
|
||||
| `<Esc>` | close FlyGrep buffer |
|
||||
| `<Enter>` | open item in current window |
|
||||
| `Ctrl-t` | open item in new tab |
|
||||
| `<Tab>` | move cursor line down |
|
||||
| `Ctrl-j` | move cursor line down |
|
||||
| `Shift-<Tab>` | move cursor line up |
|
||||
| `Ctrl-k` | move cursor line up |
|
||||
| `<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 |
|
||||
| `Ctrl-e`/`<End>` | Go to the end of the line |
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------------- | ---------------------------------- |
|
||||
| `<Esc>` | close FlyGrep buffer |
|
||||
| `<Enter>` | open file at the cursor line |
|
||||
| `Ctrl-t` | open item in new tab |
|
||||
| `Ctrl-s` | open item in split window |
|
||||
| `Ctrl-v` | open item in vertical split window |
|
||||
| `Ctrl-q` | apply all items into quickfix |
|
||||
| `<Tab>` | move cursor line down |
|
||||
| `Shift-<Tab>` | move cursor line up |
|
||||
| `<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 |
|
||||
| `Ctrl-e` / `<End>` | Go to the end of the line |
|
||||
|
@ -96,18 +96,19 @@ SpaceVim 中的搜索命令以 `SPC s` 为前缀,前一个键是使用的工
|
||||
|
||||
在 FlyGrep 内的快捷键如下:
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ------------------- | -------------------- |
|
||||
| `<Esc>` | 关闭 FlyGrep 窗口 |
|
||||
| `<Enter>` | 在当前窗口打开选中项 |
|
||||
| `Ctrl-t` | 在新标签栏打开选中项 |
|
||||
| `<Tab>` | 移动至下一行 |
|
||||
| `Ctrl-j` | 移动至下一行 |
|
||||
| `<S-Tab>` | 移动至上一行 |
|
||||
| `Ctrl-k` | 移动至上一行 |
|
||||
| `<Backspace>` | 删除光标前一个字符 |
|
||||
| `Ctrl-w` | 删除光标后的单词 |
|
||||
| `Ctrl-u` | 删除光标前所有字符 |
|
||||
| `Ctrl-k` | 删除光标后所有字符 |
|
||||
| `Ctrl-a` / `<Home>` | 将光标定位到行首 |
|
||||
| `Ctrl-e` / `<End>` | 将光标定位到行尾 |
|
||||
| 快捷键 | 功能描述 |
|
||||
| ------------------- | ------------------------- |
|
||||
| `<Esc>` | 关闭搜索窗口 |
|
||||
| `<Enter>` | 打开当前选中的文件位置 |
|
||||
| `Ctrl-t` | 在新标签栏打开选中项 |
|
||||
| `Ctrl-s` | 在分屏打开选中项 |
|
||||
| `Ctrl-v` | 在垂直分屏打开选中项 |
|
||||
| `Ctrl-q` | 将搜索结果转移至 quickfix |
|
||||
| `<Tab>` | 选中下一行文件位置 |
|
||||
| `Shift-<Tab>` | 选中上一行文件位置 |
|
||||
| `<Backspace>` | 删除上一个输入字符 |
|
||||
| `Ctrl-w` | 删除光标前的单词 |
|
||||
| `Ctrl-u` | 删除光标前所有内容 |
|
||||
| `Ctrl-k` | 删除光标后所有内容 |
|
||||
| `Ctrl-a` / `<Home>` | 将光标移至行首 |
|
||||
| `Ctrl-e` / `<End>` | 将光标移至行尾 |
|
||||
|
@ -1566,19 +1566,22 @@ endfunction
|
||||
|
||||
Flygrep 搜索窗口结果窗口内的常用快捷键:
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ------------------- | ---------------------- |
|
||||
| `<Esc>` | 关闭搜索窗口 |
|
||||
| `<Enter>` | 打开当前选中的文件位置 |
|
||||
| `Ctrl-t` | 在新标签栏打开选中项 |
|
||||
| `<Tab>` | 选中下一行文件位置 |
|
||||
| `Shift-<Tab>` | 选中上一行文件位置 |
|
||||
| `<Backspace>` | 删除上一个输入字符 |
|
||||
| `Ctrl-w` | 删除光标前的单词 |
|
||||
| `Ctrl-u` | 删除光标前所有内容 |
|
||||
| `Ctrl-k` | 删除光标后所有内容 |
|
||||
| `Ctrl-a` / `<Home>` | 将光标移至行首 |
|
||||
| `Ctrl-e` / `<End>` | 将光标移至行尾 |
|
||||
| 快捷键 | 功能描述 |
|
||||
| ------------------- | ------------------------- |
|
||||
| `<Esc>` | 关闭搜索窗口 |
|
||||
| `<Enter>` | 打开当前选中的文件位置 |
|
||||
| `Ctrl-t` | 在新标签栏打开选中项 |
|
||||
| `Ctrl-s` | 在分屏打开选中项 |
|
||||
| `Ctrl-v` | 在垂直分屏打开选中项 |
|
||||
| `Ctrl-q` | 将搜索结果转移至 quickfix |
|
||||
| `<Tab>` | 选中下一行文件位置 |
|
||||
| `Shift-<Tab>` | 选中上一行文件位置 |
|
||||
| `<Backspace>` | 删除上一个输入字符 |
|
||||
| `Ctrl-w` | 删除光标前的单词 |
|
||||
| `Ctrl-u` | 删除光标前所有内容 |
|
||||
| `Ctrl-k` | 删除光标后所有内容 |
|
||||
| `Ctrl-a` / `<Home>` | 将光标移至行首 |
|
||||
| `Ctrl-e` / `<End>` | 将光标移至行尾 |
|
||||
|
||||
#### 保持高亮
|
||||
|
||||
|
@ -1600,19 +1600,22 @@ Background search keyword in a project, when searching done, the count will be s
|
||||
|
||||
Key bindings in FlyGrep buffer:
|
||||
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------------- | --------------------------------- |
|
||||
| `<Esc>` | close FlyGrep buffer |
|
||||
| `<Enter>` | open file at the cursor line |
|
||||
| `Ctrl-t` | open item in new tab |
|
||||
| `<Tab>` | move cursor line down |
|
||||
| `Shift-<Tab>` | move cursor line up |
|
||||
| `<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 |
|
||||
| `Ctrl-e` / `<End>` | Go to the end of the line |
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------------- | ---------------------------------- |
|
||||
| `<Esc>` | close FlyGrep buffer |
|
||||
| `<Enter>` | open file at the cursor line |
|
||||
| `Ctrl-t` | open item in new tab |
|
||||
| `Ctrl-s` | open item in split window |
|
||||
| `Ctrl-v` | open item in vertical split window |
|
||||
| `Ctrl-q` | apply all items into quickfix |
|
||||
| `<Tab>` | move cursor line down |
|
||||
| `Shift-<Tab>` | move cursor line up |
|
||||
| `<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 |
|
||||
| `Ctrl-e` / `<End>` | Go to the end of the line |
|
||||
|
||||
#### Persistent highlighting
|
||||
|
||||
|
@ -30,3 +30,11 @@ Execute ( SpaceVim api: vim#buffer add_highlight):
|
||||
let nr = buffer.bufnr()
|
||||
call buffer.add_highlight(nr,'String', 1, 1, 1)
|
||||
AssertEqual highlit.syntax_at(1, 1), 'String'
|
||||
|
||||
Execute ( SpaceVim api: vim#buffer buf_get_lines):
|
||||
let buffer = SpaceVim#api#import('vim#buffer')
|
||||
let nr = buffer.bufadd('')
|
||||
call setbufvar(nr, '&buftype', 'nofile')
|
||||
call setbufvar(nr, '&buflisted', 0)
|
||||
call buffer.buf_set_lines(nr, 0, 1, 0, ['line 1', 'line 2', 'line 3', 'line 4'])
|
||||
AssertEqual buffer.buf_get_lines(nr, 1, 2, 0), ['line 2']
|
||||
|
Loading…
x
Reference in New Issue
Block a user