diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 73e0f32..88ba038 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -52,7 +52,7 @@ Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " show a directory listin Plug 'Xuyuanp/nerdtree-git-plugin', { 'on': 'NERDTreeToggle' } " show git status in nerdtree for files and dirs " Fuzzy matching -Plug 'lotabout/skim.vim' +Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' } Plug 'marty-oehme/notational-fzf-vim', { 'branch': 'origin/switch-fzf-to-skim' } Plug 'dyng/ctrlsf.vim' @@ -269,76 +269,86 @@ endfunction autocmd! User GoyoEnter nested call goyo_enter() autocmd! User GoyoLeave nested call goyo_leave() -" PLUGIN: fzf-bibtex -" Citation and Bibtex utilities -let g:bibtex_cache = '/home/marty/.cache/' -let g:bibtex_source = '/home/marty/Nextcloud/Library/academia/academia.bib' +" FZF Fuzzy Finding +" set some fzf defaults +let g:fzf_layout = { 'up': '~40%' } +let g:fzf_colors = +\ { 'fg': ['fg', 'Normal'], + \ 'bg': ['bg', 'Normal'], + \ 'hl': ['fg', 'Comment'], + \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'], + \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], + \ 'hl+': ['fg', 'Statement'], + \ 'info': ['fg', 'PreProc'], + \ 'border': ['fg', 'Ignore'], + \ 'prompt': ['fg', 'Conditional'], + \ 'pointer': ['fg', 'Exception'], + \ 'marker': ['fg', 'Keyword'], + \ 'spinner': ['fg', 'Label'], + \ 'header': ['fg', 'Comment'] } +let g:fzf_action = { + \ 'ctrl-t': 'tab split', + \ 'ctrl-x': 'split', + \ 'ctrl-v': 'vsplit' } -function! Bibtex_ls(...) - return 'bibtex-ls -cache ' . g:bibtex_cache . ' ' . g:bibtex_source . ' ' . join(a:000, ' ') +" set up fzf-bibtex +let g:fzf_bibtex_cache = '~/.cache/' +let g:fzf_bibtex_sources = g:pandoc#biblio#bibs + +" prepare bibtex_ls function to look for bib files in cwd/parent/subdirs, +" attach the standard bibtex source file +" return the command with standard cache directory filled +function! s:bibtex_ls(...) + let bibfiles = ( + \ globpath('.', '*.bib', v:true, v:true) + + \ globpath('..', '*.bib', v:true, v:true) + + \ globpath('*/', '*.bib', v:true, v:true) + \ ) + let bibfiles = join(bibfiles, ' ') + let source_cmd = 'bibtex-ls -cache ' . g:fzf_bibtex_cache . ' ' .bibfiles . ' ' . join(g:fzf_bibtex_sources) + return source_cmd endfunction -" insert citation from insert mode at cursor +" insert citation from normal mode at cursor (with brackets) +function! s:bibtex_cite_sink(lines) + let r=system("bibtex-cite ", a:lines) + execute ':normal! i[' . r . ']' +endfunction +command! -bang -nargs=* CiteRef call fzf#run(fzf#wrap({ + \ 'source': bibtex_ls(), + \ 'sink*': function('bibtex_cite_sink'), + \ 'up': '25%', + \ 'options': '--ansi --multi --prompt "Cite> "' + \ })) +" insert citation from insert mode at cursor (no brackets inserted) function! s:bibtex_cite_sink_insert(lines) let r=system("bibtex-cite ", a:lines) execute ':normal! i' . r call feedkeys('a', 'n') endfunction -inoremap @@ u:call skim#run({ - \ 'source': Bibtex_ls(), - \ 'sink*': function('bibtex_cite_sink_insert'), - \ 'up': '25%', - \ 'options': '--ansi --multi --prompt "Cite> "'}) - -" insert citation from normal mode at cursor -function! s:bibtex_cite_sink(lines) - let r=system("bibtex-cite ", a:lines) - execute ':normal! i' . r -endfunction -command! -bang -nargs=* CiteRef call skim#run({ - \ 'source': Bibtex_ls(), - \ 'sink*': function('bibtex_cite_sink'), - \ 'up': '25%', - \ 'options': '--ansi --multi --prompt "Cite> "' - \ }) - -" insert pretty formatted markdown reference +" insert markdown formatted reference function! s:bibtex_markdown_sink(lines) - let r=system("bibtex-markdown " . g:bibtex_source, a:lines) + let r=system("bibtex-markdown -cache " . g:fzf_bibtex_cache . ' ' . g:fzf_bibtex_sources, a:lines) echo join(a:lines, '; ') execute ':normal! i' . r endfunction -command! -bang -nargs=* CitePretty call skim#run({ - \ 'source': Bibtex_ls(), +command! -bang -nargs=* CiteMarkdown call fzf#run(fzf#wrap({ + \ 'source': bibtex_ls(), \ 'sink*': function('bibtex_markdown_sink'), \ 'up': '25%', \ 'options': '--ansi --multi --prompt "Markdown> "' - \ }) + \ })) -" edit the document info.yaml -" needs papis to function -" could be abstracted out to work with .bib file or the papis .yaml -" TODO THESE FUNCTIONS DO NOT WORK YET. NEED TO FIND A WAY TO GO FROM fzf -> -" papis -> editor -function! s:bibtex_edit_info_sink(lines) - echom "edit info sink: " . join(a:lines, ",") - let r=system("bibtex-cite ", a:lines) - let s=system("papis edit ref=\"" . join(a:lines,"") . "\"") - " execute ':e s' - echo s -endfunction -command! -bang -nargs=* CiteEdit call skim#run({ - \ 'source': Bibtex_ls(), - \ 'sink*': function('bibtex_edit_info_sink'), - \ 'up': '25%', - \ 'options': join([ - \ '--ansi', - \ '--with-nth=..', - \ '--preview-window=:wrap', - \ '--prompt "Edit> "', - \ '--preview=''papis edit -e cat ref="echo {} | bibtex-cite" '' ', - \ ]) - \}) +" map @@ to automatically insert citation reference at cursor +inoremap @@ u:call fzf#run(fzf#wrap({ + \ 'source': bibtex_ls(), + \ 'sink*': function('bibtex_cite_sink_insert'), + \ 'up': '25%', + \ 'options': '--ansi --multi --prompt "Cite> "'})) +" map cc to insert a complete citation at cursor +nnoremap cc :CiteRef +" map cm to insert markdown prettified citation +nnoremap cm :CiteMarkdown " PLUGIN: vim-go " change the tabstops for go to use tabs and a width of 4 diff --git a/.config/nvim/profiles/academia_fzf.vim b/.config/nvim/profiles/academia_fzf.vim index 08fba14..a5d405c 100644 --- a/.config/nvim/profiles/academia_fzf.vim +++ b/.config/nvim/profiles/academia_fzf.vim @@ -115,6 +115,7 @@ Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' } call plug#end() endif +" FZF Fuzzy Finding " set some fzf defaults let g:fzf_layout = { 'up': '~40%' } let g:fzf_colors =