Add FZF bibliography insertion
This commit is contained in:
parent
e8e8290426
commit
570c575776
2 changed files with 66 additions and 55 deletions
|
@ -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 <SID>goyo_enter()
|
||||
autocmd! User GoyoLeave nested call <SID>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': <sid>bibtex_ls(<q-args>),
|
||||
\ 'sink*': function('<sid>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 <silent> @@ <c-g>u<c-o>:call skim#run({
|
||||
\ 'source': Bibtex_ls(),
|
||||
\ 'sink*': function('<sid>bibtex_cite_sink_insert'),
|
||||
\ 'up': '25%',
|
||||
\ 'options': '--ansi --multi --prompt "Cite> "'})<CR>
|
||||
|
||||
" 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(<q-args>),
|
||||
\ 'sink*': function('<sid>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(<q-args>),
|
||||
command! -bang -nargs=* CiteMarkdown call fzf#run(fzf#wrap({
|
||||
\ 'source': <sid>bibtex_ls(),
|
||||
\ 'sink*': function('<sid>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(<q-args>),
|
||||
\ 'sink*': function('<sid>bibtex_edit_info_sink'),
|
||||
" map @@ to automatically insert citation reference at cursor
|
||||
inoremap <silent> @@ <c-g>u<c-o>:call fzf#run(fzf#wrap({
|
||||
\ 'source': <sid>bibtex_ls(),
|
||||
\ 'sink*': function('<sid>bibtex_cite_sink_insert'),
|
||||
\ 'up': '25%',
|
||||
\ 'options': join([
|
||||
\ '--ansi',
|
||||
\ '--with-nth=..',
|
||||
\ '--preview-window=:wrap',
|
||||
\ '--prompt "Edit> "',
|
||||
\ '--preview=''papis edit -e cat ref="echo {} | bibtex-cite" '' ',
|
||||
\ ])
|
||||
\})
|
||||
\ 'options': '--ansi --multi --prompt "Cite> "'}))<CR>
|
||||
" map <leader>cc to insert a complete citation at cursor
|
||||
nnoremap <silent> <leader>cc :CiteRef<cr>
|
||||
" map <leader>cm to insert markdown prettified citation
|
||||
nnoremap <silent> <leader>cm :CiteMarkdown<cr>
|
||||
|
||||
" PLUGIN: vim-go
|
||||
" change the tabstops for go to use tabs and a width of 4
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue