mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
Add fzf layer (#1504)
This commit is contained in:
parent
44cdf7774c
commit
f993796d6e
42
autoload/SpaceVim/api/vim.vim
Normal file
42
autoload/SpaceVim/api/vim.vim
Normal file
@ -0,0 +1,42 @@
|
||||
let s:self = {}
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
|
||||
function! s:self.jumps() abort
|
||||
let result = []
|
||||
for jump in split(s:CMP.execute('jumps'), '\n')[1:]
|
||||
let list = split(jump)
|
||||
if len(list) < 4
|
||||
continue
|
||||
endif
|
||||
|
||||
let [linenr, col, file_text] = [list[1], list[2]+1, join(list[3:])]
|
||||
let lines = getbufline(file_text, linenr)
|
||||
let path = file_text
|
||||
let bufnr = bufnr(file_text)
|
||||
if empty(lines)
|
||||
if stridx(join(split(getline(linenr))), file_text) == 0
|
||||
let lines = [file_text]
|
||||
let path = bufname('%')
|
||||
let bufnr = bufnr('%')
|
||||
elseif filereadable(path)
|
||||
let bufnr = 0
|
||||
let lines = ['buffer unloaded']
|
||||
else
|
||||
" Skip.
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
|
||||
if getbufvar(bufnr, '&filetype') ==# 'unite'
|
||||
" Skip unite buffer.
|
||||
continue
|
||||
endif
|
||||
|
||||
call add(result, [linenr, col, file_text, path, bufnr, lines])
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#api#vim#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
@ -60,6 +60,7 @@ function! s:self.debug() abort
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! SpaceVim#api#vim#command#get()
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
@ -144,11 +144,6 @@ function! SpaceVim#default#layers() abort
|
||||
call SpaceVim#layers#load('core#banner')
|
||||
call SpaceVim#layers#load('core#statusline')
|
||||
call SpaceVim#layers#load('core#tabline')
|
||||
if has('python3')
|
||||
call SpaceVim#layers#load('denite')
|
||||
else
|
||||
call SpaceVim#layers#load('unite')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#default#keyBindings() abort
|
||||
|
@ -320,6 +320,9 @@ function! SpaceVim#layers#core#statusline#get(...) abort
|
||||
elseif &filetype ==# 'SpaceVimTabsManager'
|
||||
return '%#SpaceVim_statusline_a#' . s:winnr(1) . '%#SpaceVim_statusline_a_SpaceVim_statusline_b#' . s:lsep
|
||||
\ . '%#SpaceVim_statusline_b# TabsManager %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep
|
||||
elseif &filetype ==# 'fzf'
|
||||
return '%#SpaceVim_statusline_a_bold# FZF %#SpaceVim_statusline_a_SpaceVim_statusline_b#' . s:lsep
|
||||
\ . '%#SpaceVim_statusline_b# %{SpaceVim#layers#fzf#sources()} %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep
|
||||
elseif &filetype ==# 'denite'
|
||||
return '%#SpaceVim_statusline_a_bold# %{SpaceVim#layers#core#statusline#denite_mode()} '
|
||||
\ . '%#SpaceVim_statusline_a_bold_SpaceVim_statusline_b#' . s:lsep . ' '
|
||||
|
313
autoload/SpaceVim/layers/fzf.vim
Normal file
313
autoload/SpaceVim/layers/fzf.vim
Normal file
@ -0,0 +1,313 @@
|
||||
"=============================================================================
|
||||
" fzf.vim --- fzf layer for SpaceVim
|
||||
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg at 163.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
|
||||
|
||||
function! SpaceVim#layers#fzf#plugins() abort
|
||||
let plugins = []
|
||||
call add(plugins, ['junegunn/fzf', { 'merged' : 0}])
|
||||
call add(plugins, ['Shougo/neoyank.vim', {'merged' : 0}])
|
||||
call add(plugins, ['SpaceVim/fzf-neoyank', { 'merged' : 0}])
|
||||
return plugins
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#layers#fzf#config() abort
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['j', 'i'], 'Denite outline', 'jump to a definition in buffer', 1)
|
||||
nnoremap <silent> <C-p> :FzfFiles<cr>
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['T', 's'], 'FzfColors', 'fuzzy find colorschemes', 1)
|
||||
let g:_spacevim_mappings.f = {'name' : '+Fuzzy Finder'}
|
||||
call s:defind_fuzzy_finder()
|
||||
endfunction
|
||||
|
||||
let s:file = expand('<sfile>:~')
|
||||
let s:unite_lnum = expand('<slnum>') + 3
|
||||
function! s:defind_fuzzy_finder() abort
|
||||
nnoremap <silent> <Leader>fe
|
||||
\ :<C-u>FzfRegister<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.e = ['FzfRegister',
|
||||
\ 'fuzzy find registers',
|
||||
\ [
|
||||
\ '[Leader f r ] is to resume unite window',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fj
|
||||
\ :<C-u>FzfJumps<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.j = ['FzfJumps',
|
||||
\ 'fuzzy find jump list',
|
||||
\ [
|
||||
\ '[Leader f j] is to fuzzy find jump list',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fh
|
||||
\ :<C-u>FZFNeoyank<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.h = ['FZFNeoyank',
|
||||
\ 'fuzzy find yank history',
|
||||
\ [
|
||||
\ '[Leader f r ] is to resume unite window',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fm
|
||||
\ :<C-u>FzfMessages<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.m = ['FzfMessages',
|
||||
\ 'fuzzy find message',
|
||||
\ [
|
||||
\ '[Leader f m] is to fuzzy find message',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fq
|
||||
\ :<C-u>FzfQuickfix<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.q = ['FzfQuickfix',
|
||||
\ 'fuzzy find quickfix list',
|
||||
\ [
|
||||
\ '[Leader f q] is to fuzzy find quickfix list',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fl
|
||||
\ :<C-u>FzfLocationList<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.l = ['FzfLocationList',
|
||||
\ 'fuzzy find location list',
|
||||
\ [
|
||||
\ '[Leader f l] is to fuzzy find location list',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fo :<C-u>FzfOutline<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.o = ['FzfOutline',
|
||||
\ 'fuzzy find outline',
|
||||
\ [
|
||||
\ '[Leader f o] is to fuzzy find outline',
|
||||
\ '',
|
||||
\ 'Definition: ' . s:file . ':' . lnum,
|
||||
\ ]
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
command! FzfColors call <SID>colors()
|
||||
function! s:colors() abort
|
||||
let s:source = 'colorscheme'
|
||||
call fzf#run({'source': map(split(globpath(&rtp, 'colors/*.vim')),
|
||||
\ "fnamemodify(v:val, ':t:r')"),
|
||||
\ 'sink': 'colo', 'down': '40%'})
|
||||
endfunction
|
||||
|
||||
command! FzfFiles call <SID>files()
|
||||
function! s:files() abort
|
||||
let s:source = 'files'
|
||||
call fzf#run({'sink': 'e', 'options': '--reverse', 'down' : '40%'})
|
||||
endfunction
|
||||
|
||||
let s:source = ''
|
||||
|
||||
function! SpaceVim#layers#fzf#sources() abort
|
||||
|
||||
return s:source
|
||||
|
||||
endfunction
|
||||
command! FzfJumps call <SID>jumps()
|
||||
function! s:bufopen(e) abort
|
||||
let list = split(a:e)
|
||||
if len(list) < 4
|
||||
return
|
||||
endif
|
||||
|
||||
let [linenr, col, file_text] = [list[1], list[2]+1, join(list[3:])]
|
||||
let lines = getbufline(file_text, linenr)
|
||||
let path = file_text
|
||||
let bufnr = bufnr(file_text)
|
||||
if empty(lines)
|
||||
if stridx(join(split(getline(linenr))), file_text) == 0
|
||||
let lines = [file_text]
|
||||
let path = bufname('%')
|
||||
let bufnr = bufnr('%')
|
||||
elseif filereadable(path)
|
||||
let bufnr = 0
|
||||
let lines = ['buffer unloaded']
|
||||
else
|
||||
" Skip.
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
exe 'e ' . path
|
||||
call cursor(linenr, col)
|
||||
endfunction
|
||||
function! s:jumps() abort
|
||||
let s:source = 'jumps'
|
||||
function! s:jumplist() abort
|
||||
return split(s:CMP.execute('jumps'), '\n')[1:]
|
||||
endfunction
|
||||
call fzf#run({
|
||||
\ 'source': reverse(<sid>jumplist()),
|
||||
\ 'sink': function('s:bufopen'),
|
||||
\ 'options': '+m',
|
||||
\ 'down': len(<sid>jumplist()) + 2
|
||||
\ })
|
||||
endfunction
|
||||
command! FzfMessages call <SID>message()
|
||||
function! s:yankmessage(e) abort
|
||||
let @" = a:e
|
||||
echohl ModeMsg
|
||||
echo 'Yanked'
|
||||
echohl None
|
||||
endfunction
|
||||
function! s:message() abort
|
||||
let s:source = 'message'
|
||||
function! s:messagelist() abort
|
||||
return split(s:CMP.execute('message'), '\n')
|
||||
endfunction
|
||||
call fzf#run({
|
||||
\ 'source': reverse(<sid>messagelist()),
|
||||
\ 'sink': function('s:yankmessage'),
|
||||
\ 'options': '+m',
|
||||
\ 'down': len(<sid>messagelist()) + 2
|
||||
\ })
|
||||
endfunction
|
||||
|
||||
command! FzfQuickfix call s:quickfix()
|
||||
function! s:open_quickfix_item(e) abort
|
||||
let line = a:e
|
||||
let filename = fnameescape(split(line, ':\d\+:')[0])
|
||||
let linenr = matchstr(line, ':\d\+:')[1:-2]
|
||||
let colum = matchstr(line, '\(:\d\+\)\@<=:\d\+:')[1:-2]
|
||||
exe 'e ' . filename
|
||||
call cursor(linenr, colum)
|
||||
endfunction
|
||||
function! s:quickfix_to_grep(v) abort
|
||||
return bufname(a:v.bufnr) . ':' . a:v.lnum . ':' . a:v.col . ':' . a:v.text
|
||||
endfunction
|
||||
function! s:quickfix() abort
|
||||
let s:source = 'quickfix'
|
||||
function! s:quickfix_list() abort
|
||||
return map(getqflist(), 's:quickfix_to_grep(v:val)')
|
||||
endfunction
|
||||
call fzf#run({
|
||||
\ 'source': reverse(<sid>quickfix_list()),
|
||||
\ 'sink': function('s:open_quickfix_item'),
|
||||
\ 'options': '--reverse',
|
||||
\ 'down' : '40%',
|
||||
\ })
|
||||
endfunction
|
||||
command! FzfLocationList call s:location_list()
|
||||
function! s:location_list_to_grep(v) abort
|
||||
return bufname(a:v.bufnr) . ':' . a:v.lnum . ':' . a:v.col . ':' . a:v.text
|
||||
endfunction
|
||||
function! s:open_location_item(e) abort
|
||||
let line = a:e
|
||||
let filename = fnameescape(split(line, ':\d\+:')[0])
|
||||
let linenr = matchstr(line, ':\d\+:')[1:-2]
|
||||
let colum = matchstr(line, '\(:\d\+\)\@<=:\d\+:')[1:-2]
|
||||
exe 'e ' . filename
|
||||
call cursor(linenr, colum)
|
||||
endfunction
|
||||
function! s:location_list() abort
|
||||
let s:source = 'location_list'
|
||||
function! s:get_location_list() abort
|
||||
return map(getloclist(0), 's:location_list_to_grep(v:val)')
|
||||
endfunction
|
||||
call fzf#run({
|
||||
\ 'source': reverse(<sid>get_location_list()),
|
||||
\ 'sink': function('s:open_location_item'),
|
||||
\ 'options': '--reverse',
|
||||
\ 'down' : '40%',
|
||||
\ })
|
||||
endfunction
|
||||
|
||||
|
||||
command! -bang FzfOutline call fzf#run(fzf#wrap('outline', s:outline(), <bang>0))
|
||||
function! s:outline_format(lists) abort
|
||||
for list in a:lists
|
||||
let linenr = list[2][:len(list[2])-3]
|
||||
let line = getline(linenr)
|
||||
let idx = stridx(line, list[0])
|
||||
let len = len(list[0])
|
||||
let list[0] = line[:idx-1] . printf("\x1b[%s%sm%s\x1b[m", 34, '', line[idx : idx+len-1]) . line[idx + len :]
|
||||
endfor
|
||||
for list in a:lists
|
||||
call map(list, "printf('%s', v:val)")
|
||||
endfor
|
||||
return a:lists
|
||||
endfunction
|
||||
|
||||
function! s:outline_source(tag_cmds) abort
|
||||
if !filereadable(expand('%'))
|
||||
throw 'Save the file first'
|
||||
endif
|
||||
|
||||
for cmd in a:tag_cmds
|
||||
let lines = split(system(cmd), "\n")
|
||||
if !v:shell_error
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
if v:shell_error
|
||||
throw get(lines, 0, 'Failed to extract tags')
|
||||
elseif empty(lines)
|
||||
throw 'No tags found'
|
||||
endif
|
||||
return map(s:outline_format(map(lines, 'split(v:val, "\t")')), 'join(v:val, "\t")')
|
||||
endfunction
|
||||
|
||||
function! s:outline_sink(lines) abort
|
||||
if !empty(a:lines)
|
||||
let line = a:lines[0]
|
||||
execute split(line, "\t")[2]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:outline(...) abort
|
||||
let s:source = 'outline'
|
||||
let args = copy(a:000)
|
||||
let tag_cmds = [
|
||||
\ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s 2>/dev/null', &filetype, expand('%:S')),
|
||||
\ printf('ctags -f - --sort=no --excmd=number %s 2>/dev/null', expand('%:S'))]
|
||||
return {
|
||||
\ 'source': s:outline_source(tag_cmds),
|
||||
\ 'sink*': function('s:outline_sink'),
|
||||
\ 'options': '--reverse +m -d "\t" --with-nth 1 -n 1 --ansi --prompt "Outline> "'}
|
||||
endfunction
|
||||
|
||||
|
||||
command! FzfRegister call <SID>register()
|
||||
function! s:yankregister(e) abort
|
||||
let @" = a:e
|
||||
echohl ModeMsg
|
||||
echo 'Yanked'
|
||||
echohl None
|
||||
endfunction
|
||||
function! s:register() abort
|
||||
let s:source = 'registers'
|
||||
function! s:registers_list() abort
|
||||
return split(s:CMP.execute('registers'), '\n')[1:]
|
||||
endfunction
|
||||
call fzf#run({
|
||||
\ 'source': reverse(<sid>registers_list()),
|
||||
\ 'sink': function('s:yankregister'),
|
||||
\ 'options': '+m',
|
||||
\ 'down': '40%'
|
||||
\ })
|
||||
endfunction
|
@ -36,7 +36,6 @@ function! SpaceVim#layers#tools#plugins() abort
|
||||
\ ['itchyny/calendar.vim', { 'on_cmd' : 'Calendar'}],
|
||||
\ ['wsdjeg/Mysql.vim', { 'on_cmd' : 'SQLGetConnection'}],
|
||||
\ ['wsdjeg/job.vim', { 'merged' : 0}],
|
||||
\ ['junegunn/fzf', { 'on_cmd' : 'FZF'}],
|
||||
\ ['ianva/vim-youdao-translater', { 'on_cmd' : ['Ydv','Ydc','Yde']}],
|
||||
\ ['vim-scripts/TaskList.vim', { 'on_cmd' : 'TaskList'}],
|
||||
\ ['MarcWeber/vim-addon-mw-utils'],
|
||||
|
26
docs/layers/fzf.md
Normal file
26
docs/layers/fzf.md
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
title: "SpaceVim fzf layer"
|
||||
description: "This layers provide a heavily customized fzf centric work-flow"
|
||||
---
|
||||
|
||||
# [SpaceVim Layers:](https://spacevim.org/layers) fzf
|
||||
|
||||
## Intro
|
||||
|
||||
This layer is a heavily customized warpper for fzf.
|
||||
|
||||
|
||||
## Key bindings
|
||||
|
||||
| Key bindings | Discription |
|
||||
| -------------------- | ----------------------------- |
|
||||
| `<Leader> f <space>` | Fuzzy find menu:CustomKeyMaps |
|
||||
| `<Leader> f e` | Fuzzy find register |
|
||||
| `<Leader> f f` | Fuzzy find file |
|
||||
| `<Leader> f h` | Fuzzy find history/yank |
|
||||
| `<Leader> f j` | Fuzzy find jump, change |
|
||||
| `<Leader> f l` | Fuzzy find location list |
|
||||
| `<Leader> f m` | Fuzzy find output messages |
|
||||
| `<Leader> f o` | Fuzzy find outline |
|
||||
| `<Leader> f q` | Fuzzy find quick fix |
|
||||
| `<Leader> f r` | Resumes Unite window |
|
@ -47,6 +47,7 @@ call SpaceVim#layers#disable('shell')
|
||||
|
||||
| Name | Description |
|
||||
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [VersionControl](https://spacevim.org/layers/VersionControl/) | This layers provides general version control feature for vim. It should work with all VC backends such as Git, Mercurial, Bazaar, SVN, etc… |
|
||||
| [autocomplete](https://spacevim.org/layers/autocomplete/) | This layer provides auto-completion to SpaceVim |
|
||||
| [chat](https://spacevim.org/layers/chat/) | SpaceVim chatting layer provide chatting with qq and weixin in vim. |
|
||||
| [checkers](https://spacevim.org/layers/checkers/) | This layer provides syntax checking feature |
|
||||
@ -56,10 +57,10 @@ call SpaceVim#layers#disable('shell')
|
||||
| [ctrlp](https://spacevim.org/layers/ctrlp/) | This layers adds extensive support for git |
|
||||
| [debug](https://spacevim.org/layers/debug/) | This layer provide debug workflow support in SpaceVim |
|
||||
| [default](https://spacevim.org/layers/default/) | lt layer contains none plugins, but it has some better default config for vim and neovim |
|
||||
| [denite](https://spacevim.org/layers/denite/) | Another Unite centric work-flow which use denite |
|
||||
| [denite](https://spacevim.org/layers/denite/) | This layers provide a heavily customized Denite centric work-flow |
|
||||
| [fzf](https://spacevim.org/layers/fzf/) | This layers provide a heavily customized fzf centric work-flow |
|
||||
| [git](https://spacevim.org/layers/git/) | This layers adds extensive support for git |
|
||||
| [github](https://spacevim.org/layers/github/) | This layer provides GitHub integration for SpaceVim |
|
||||
| [index](https://spacevim.org/layers/index/) | list of available layers in SpaceVim |
|
||||
| [lang#c](https://spacevim.org/layers/lang/c/) | This layer is for c/c++/object-c development |
|
||||
| [lang#csharp](https://spacevim.org/layers/lang/csharp/) | This layer is for csharp development |
|
||||
| [lang#dart](https://spacevim.org/layers/lang/dart/) | This layer is for dart development, provide autocompletion, syntax checking, code format for dart file. |
|
||||
@ -83,6 +84,7 @@ call SpaceVim#layers#disable('shell')
|
||||
| [tags](https://spacevim.org/layers/tags/) | This layer provide tags manager for project |
|
||||
| [tools#dash](https://spacevim.org/layers/tools/dash/) | This layer provides Dash integration for SpaceVim |
|
||||
| [ui](https://spacevim.org/layers/ui/) | Awesome UI layer for SpaceVim, provide IDE-like UI for neovim and vim in both TUI and GUI |
|
||||
| [unite](https://spacevim.org/layers/unite/) | This layers provide a heavily customized Unite centric work-flow |
|
||||
|
||||
<!-- SpaceVim layer list end -->
|
||||
|
||||
|
@ -46,4 +46,4 @@ by default, when open a cmd, the current dir is your Home directory, run this co
|
||||
|
||||
```bash
|
||||
git clone https://github.com/SpaceVim/SpaceVim.git AppData\Local\nvim
|
||||
```
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user