diff --git a/autoload/SpaceVim/api/vim.vim b/autoload/SpaceVim/api/vim.vim new file mode 100644 index 000000000..f9f3203c1 --- /dev/null +++ b/autoload/SpaceVim/api/vim.vim @@ -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 diff --git a/autoload/SpaceVim/api/vim/command.vim b/autoload/SpaceVim/api/vim/command.vim index 0aefde062..17d4e1acc 100644 --- a/autoload/SpaceVim/api/vim/command.vim +++ b/autoload/SpaceVim/api/vim/command.vim @@ -60,6 +60,7 @@ function! s:self.debug() abort endfunction + function! SpaceVim#api#vim#command#get() return deepcopy(s:self) endfunction diff --git a/autoload/SpaceVim/default.vim b/autoload/SpaceVim/default.vim index 81644b894..7e20e9082 100644 --- a/autoload/SpaceVim/default.vim +++ b/autoload/SpaceVim/default.vim @@ -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 diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index a43732780..b6f523e8f 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -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 . ' ' diff --git a/autoload/SpaceVim/layers/fzf.vim b/autoload/SpaceVim/layers/fzf.vim new file mode 100644 index 000000000..7cdd75129 --- /dev/null +++ b/autoload/SpaceVim/layers/fzf.vim @@ -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 :FzfFiles + 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(':~') +let s:unite_lnum = expand('') + 3 +function! s:defind_fuzzy_finder() abort + nnoremap fe + \ :FzfRegister + let lnum = expand('') + 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 fj + \ :FzfJumps + let lnum = expand('') + 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 fh + \ :FZFNeoyank + let lnum = expand('') + 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 fm + \ :FzfMessages + let lnum = expand('') + 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 fq + \ :FzfQuickfix + let lnum = expand('') + 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 fl + \ :FzfLocationList + let lnum = expand('') + 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 fo :FzfOutline + let lnum = expand('') + 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 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 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 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(jumplist()), + \ 'sink': function('s:bufopen'), + \ 'options': '+m', + \ 'down': len(jumplist()) + 2 + \ }) +endfunction +command! FzfMessages call 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(messagelist()), + \ 'sink': function('s:yankmessage'), + \ 'options': '+m', + \ 'down': len(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(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(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(), 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 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(registers_list()), + \ 'sink': function('s:yankregister'), + \ 'options': '+m', + \ 'down': '40%' + \ }) +endfunction diff --git a/autoload/SpaceVim/layers/tools.vim b/autoload/SpaceVim/layers/tools.vim index 70e62f40f..a12d2ee1f 100644 --- a/autoload/SpaceVim/layers/tools.vim +++ b/autoload/SpaceVim/layers/tools.vim @@ -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'], diff --git a/docs/layers/fzf.md b/docs/layers/fzf.md new file mode 100644 index 000000000..65e1956c0 --- /dev/null +++ b/docs/layers/fzf.md @@ -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 | +| -------------------- | ----------------------------- | +| ` f ` | Fuzzy find menu:CustomKeyMaps | +| ` f e` | Fuzzy find register | +| ` f f` | Fuzzy find file | +| ` f h` | Fuzzy find history/yank | +| ` f j` | Fuzzy find jump, change | +| ` f l` | Fuzzy find location list | +| ` f m` | Fuzzy find output messages | +| ` f o` | Fuzzy find outline | +| ` f q` | Fuzzy find quick fix | +| ` f r` | Resumes Unite window | diff --git a/docs/layers/index.md b/docs/layers/index.md index 18ff5ffa9..397702df2 100644 --- a/docs/layers/index.md +++ b/docs/layers/index.md @@ -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 | diff --git a/wiki/en/Installing-SpaceVim.md b/wiki/en/Installing-SpaceVim.md index a7317d92e..c5fc4a34b 100644 --- a/wiki/en/Installing-SpaceVim.md +++ b/wiki/en/Installing-SpaceVim.md @@ -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 -``` \ No newline at end of file +```