mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 10:15: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
|
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
|
fu! SpaceVim#api#vim#buffer#get() abort
|
||||||
return deepcopy(s:self)
|
return deepcopy(s:self)
|
||||||
|
@ -578,6 +578,30 @@ function! s:open_item_horizontally() abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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
|
function! s:double_click() abort
|
||||||
if line('.') !=# ''
|
if line('.') !=# ''
|
||||||
if s:grepid != 0
|
if s:grepid != 0
|
||||||
@ -764,6 +788,7 @@ let s:MPT._function_key = {
|
|||||||
\ "\<C-f>" : function('s:start_filter'),
|
\ "\<C-f>" : function('s:start_filter'),
|
||||||
\ "\<C-v>" : function('s:open_item_vertically'),
|
\ "\<C-v>" : function('s:open_item_vertically'),
|
||||||
\ "\<C-s>" : function('s:open_item_horizontally'),
|
\ "\<C-s>" : function('s:open_item_horizontally'),
|
||||||
|
\ "\<C-q>" : function('s:apply_to_quickfix'),
|
||||||
\ "\<M-r>" : function('s:start_replace'),
|
\ "\<M-r>" : function('s:start_replace'),
|
||||||
\ "\<C-p>" : function('s:toggle_preview'),
|
\ "\<C-p>" : function('s:toggle_preview'),
|
||||||
\ "\<C-e>" : function('s:toggle_expr_mode'),
|
\ "\<C-e>" : function('s:toggle_expr_mode'),
|
||||||
|
@ -82,18 +82,19 @@ The available scopes and corresponding keys are:
|
|||||||
|
|
||||||
**Within FlyGrep buffer:**
|
**Within FlyGrep buffer:**
|
||||||
|
|
||||||
| Key Bindings | Descriptions |
|
| Key Bindings | Descriptions |
|
||||||
| ----------------- | --------------------------------- |
|
| ------------------- | ---------------------------------- |
|
||||||
| `<Esc>` | close FlyGrep buffer |
|
| `<Esc>` | close FlyGrep buffer |
|
||||||
| `<Enter>` | open item in current window |
|
| `<Enter>` | open file at the cursor line |
|
||||||
| `Ctrl-t` | open item in new tab |
|
| `Ctrl-t` | open item in new tab |
|
||||||
| `<Tab>` | move cursor line down |
|
| `Ctrl-s` | open item in split window |
|
||||||
| `Ctrl-j` | move cursor line down |
|
| `Ctrl-v` | open item in vertical split window |
|
||||||
| `Shift-<Tab>` | move cursor line up |
|
| `Ctrl-q` | apply all items into quickfix |
|
||||||
| `Ctrl-k` | move cursor line up |
|
| `<Tab>` | move cursor line down |
|
||||||
| `<Backspace>` | remove last character |
|
| `Shift-<Tab>` | move cursor line up |
|
||||||
| `Ctrl-w` | remove the word before the cursor |
|
| `<BackSpace>` | remove last character |
|
||||||
| `Ctrl-u` | remove the line before the cursor |
|
| `Ctrl-w` | remove the Word before the cursor |
|
||||||
| `Ctrl-k` | remove the line after the cursor |
|
| `Ctrl-u` | remove the Line before the cursor |
|
||||||
| `Ctrl-a`/`<Home>` | Go to the beginning of the line |
|
| `Ctrl-k` | remove the Line after the cursor |
|
||||||
| `Ctrl-e`/`<End>` | Go to the end of the line |
|
| `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 内的快捷键如下:
|
在 FlyGrep 内的快捷键如下:
|
||||||
|
|
||||||
| 快捷键 | 功能描述 |
|
| 快捷键 | 功能描述 |
|
||||||
| ------------------- | -------------------- |
|
| ------------------- | ------------------------- |
|
||||||
| `<Esc>` | 关闭 FlyGrep 窗口 |
|
| `<Esc>` | 关闭搜索窗口 |
|
||||||
| `<Enter>` | 在当前窗口打开选中项 |
|
| `<Enter>` | 打开当前选中的文件位置 |
|
||||||
| `Ctrl-t` | 在新标签栏打开选中项 |
|
| `Ctrl-t` | 在新标签栏打开选中项 |
|
||||||
| `<Tab>` | 移动至下一行 |
|
| `Ctrl-s` | 在分屏打开选中项 |
|
||||||
| `Ctrl-j` | 移动至下一行 |
|
| `Ctrl-v` | 在垂直分屏打开选中项 |
|
||||||
| `<S-Tab>` | 移动至上一行 |
|
| `Ctrl-q` | 将搜索结果转移至 quickfix |
|
||||||
| `Ctrl-k` | 移动至上一行 |
|
| `<Tab>` | 选中下一行文件位置 |
|
||||||
| `<Backspace>` | 删除光标前一个字符 |
|
| `Shift-<Tab>` | 选中上一行文件位置 |
|
||||||
| `Ctrl-w` | 删除光标后的单词 |
|
| `<Backspace>` | 删除上一个输入字符 |
|
||||||
| `Ctrl-u` | 删除光标前所有字符 |
|
| `Ctrl-w` | 删除光标前的单词 |
|
||||||
| `Ctrl-k` | 删除光标后所有字符 |
|
| `Ctrl-u` | 删除光标前所有内容 |
|
||||||
| `Ctrl-a` / `<Home>` | 将光标定位到行首 |
|
| `Ctrl-k` | 删除光标后所有内容 |
|
||||||
| `Ctrl-e` / `<End>` | 将光标定位到行尾 |
|
| `Ctrl-a` / `<Home>` | 将光标移至行首 |
|
||||||
|
| `Ctrl-e` / `<End>` | 将光标移至行尾 |
|
||||||
|
@ -1566,19 +1566,22 @@ endfunction
|
|||||||
|
|
||||||
Flygrep 搜索窗口结果窗口内的常用快捷键:
|
Flygrep 搜索窗口结果窗口内的常用快捷键:
|
||||||
|
|
||||||
| 快捷键 | 功能描述 |
|
| 快捷键 | 功能描述 |
|
||||||
| ------------------- | ---------------------- |
|
| ------------------- | ------------------------- |
|
||||||
| `<Esc>` | 关闭搜索窗口 |
|
| `<Esc>` | 关闭搜索窗口 |
|
||||||
| `<Enter>` | 打开当前选中的文件位置 |
|
| `<Enter>` | 打开当前选中的文件位置 |
|
||||||
| `Ctrl-t` | 在新标签栏打开选中项 |
|
| `Ctrl-t` | 在新标签栏打开选中项 |
|
||||||
| `<Tab>` | 选中下一行文件位置 |
|
| `Ctrl-s` | 在分屏打开选中项 |
|
||||||
| `Shift-<Tab>` | 选中上一行文件位置 |
|
| `Ctrl-v` | 在垂直分屏打开选中项 |
|
||||||
| `<Backspace>` | 删除上一个输入字符 |
|
| `Ctrl-q` | 将搜索结果转移至 quickfix |
|
||||||
| `Ctrl-w` | 删除光标前的单词 |
|
| `<Tab>` | 选中下一行文件位置 |
|
||||||
| `Ctrl-u` | 删除光标前所有内容 |
|
| `Shift-<Tab>` | 选中上一行文件位置 |
|
||||||
| `Ctrl-k` | 删除光标后所有内容 |
|
| `<Backspace>` | 删除上一个输入字符 |
|
||||||
| `Ctrl-a` / `<Home>` | 将光标移至行首 |
|
| `Ctrl-w` | 删除光标前的单词 |
|
||||||
| `Ctrl-e` / `<End>` | 将光标移至行尾 |
|
| `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 in FlyGrep buffer:
|
||||||
|
|
||||||
| Key Bindings | Descriptions |
|
| Key Bindings | Descriptions |
|
||||||
| ------------------- | --------------------------------- |
|
| ------------------- | ---------------------------------- |
|
||||||
| `<Esc>` | close FlyGrep buffer |
|
| `<Esc>` | close FlyGrep buffer |
|
||||||
| `<Enter>` | open file at the cursor line |
|
| `<Enter>` | open file at the cursor line |
|
||||||
| `Ctrl-t` | open item in new tab |
|
| `Ctrl-t` | open item in new tab |
|
||||||
| `<Tab>` | move cursor line down |
|
| `Ctrl-s` | open item in split window |
|
||||||
| `Shift-<Tab>` | move cursor line up |
|
| `Ctrl-v` | open item in vertical split window |
|
||||||
| `<BackSpace>` | remove last character |
|
| `Ctrl-q` | apply all items into quickfix |
|
||||||
| `Ctrl-w` | remove the Word before the cursor |
|
| `<Tab>` | move cursor line down |
|
||||||
| `Ctrl-u` | remove the Line before the cursor |
|
| `Shift-<Tab>` | move cursor line up |
|
||||||
| `Ctrl-k` | remove the Line after the cursor |
|
| `<BackSpace>` | remove last character |
|
||||||
| `Ctrl-a` / `<Home>` | Go to the beginning of the line |
|
| `Ctrl-w` | remove the Word before the cursor |
|
||||||
| `Ctrl-e` / `<End>` | Go to the end of the line |
|
| `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
|
#### Persistent highlighting
|
||||||
|
|
||||||
|
@ -30,3 +30,11 @@ Execute ( SpaceVim api: vim#buffer add_highlight):
|
|||||||
let nr = buffer.bufnr()
|
let nr = buffer.bufnr()
|
||||||
call buffer.add_highlight(nr,'String', 1, 1, 1)
|
call buffer.add_highlight(nr,'String', 1, 1, 1)
|
||||||
AssertEqual highlit.syntax_at(1, 1), 'String'
|
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