1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-22 17:05:42 +08:00

Improve foldsearch layer (#3492)

This commit is contained in:
Wang Shidong 2020-04-27 23:28:19 +08:00 committed by GitHub
parent d0fe6fcda1
commit b181a3542f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 10 deletions

View File

@ -31,6 +31,28 @@ function! SpaceVim#layers#foldsearch#config()
\ ] \ ]
\ ], \ ],
\ 1) \ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['F', 'W'], 'call call('
\ . string(s:_function('s:foldsearch_cursor')) . ', [])',
\ ['foldsearch-cword',
\ [
\ 'SPC F W is to foldsearch cursor word',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['F', 'e'], 'call call('
\ . string(s:_function('s:foldsearch_expr')) . ', [])',
\ ['foldsearch-regexp',
\ [
\ 'SPC F e is to foldsearch regular expression',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
endfunction endfunction
function! s:foldsearch_word() abort function! s:foldsearch_word() abort
@ -40,6 +62,20 @@ function! s:foldsearch_word() abort
endif endif
endfunction endfunction
function! s:foldsearch_cursor() abort
let word = expand('<cword>')
if !empty(word)
call SpaceVim#plugins#foldsearch#word(word)
endif
endfunction
function! s:foldsearch_expr() abort
let word = input('foldsearch expr >')
if !empty(word)
call SpaceVim#plugins#foldsearch#expr(word)
endif
endfunction
" function() wrapper " function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170') if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort function! s:_function(fstr) abort

View File

@ -10,7 +10,7 @@ let s:JOB = SpaceVim#api#import('job')
let s:matched_lines = [] let s:matched_lines = []
function! SpaceVim#plugins#foldsearch#word(word) function! SpaceVim#plugins#foldsearch#word(word)
let argv = ['rg', '--line-number', a:word] let argv = ['rg', '--line-number', '--fixed-strings', a:word]
call s:foldsearch(argv) call s:foldsearch(argv)
endfunction endfunction

View File

@ -27,8 +27,12 @@ lang: zh
name = "foldsearch" name = "foldsearch"
``` ```
该模块依赖于命令:[ripgrep](https://github.com/BurntSushi/ripgrep)。
## 快捷键 ## 快捷键
| 快捷键 | 功能描述 | | 快捷键 | 功能描述 |
| --------- | --------------- | | --------- | ----------------------------- |
| `SPC F w` | Foldsearch word | | `SPC F w` | foldsearch input word |
| `SPC F W` | foldsearch cursor word |
| `SPC F e` | foldsearch regular expression |

View File

@ -7,23 +7,32 @@ description: "This layer provides functions that fold away lines that don't matc
<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc GFM -->
- [Description](#description) - [Intro](#intro)
- [Install](#install)
- [Key bindings](#key-bindings) - [Key bindings](#key-bindings)
<!-- vim-markdown-toc --> <!-- vim-markdown-toc -->
## Description ## Intro
This layer provides functions that fold away lines that don't match a specific search pattern. This layer provides functions that fold away lines that don't match a specific search pattern.
The search pattern can be a word or a regular expression. To enable this layer: The search pattern can be a word or a regular expression.
## Install
To use this layer, add it to your configuration file.
```toml ```toml
[layers] [layers]
name = "foldsearch" name = "foldsearch"
``` ```
This layer requires [ripgrep](https://github.com/BurntSushi/ripgrep).
## Key bindings ## Key bindings
| Key bindings | Description | | Key bindings | Description |
| ------------ | --------------------- | | ------------ | ----------------------------- |
| `SPC F w` | foldsearch input word | | `SPC F w` | foldsearch input word |
| `SPC F W` | foldsearch cursor word |
| `SPC F e` | foldsearch regular expression |