Initial commit
This commit is contained in:
commit
471e93d294
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# The `papis-vim` package
|
||||||
|
|
||||||
|
This package provides Vim support for [Papis](https://papis.readthedocs.io/en/latest/), command-line based bibliography manager.
|
||||||
|
|
||||||
|
[Screencast](https://asciinema.org/a/VkKJJYA3RRO4bHnw7Sgkoy2ZB)
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
This package depends on [fzf.vim](https://github.com/junegunn/fzf.vim).
|
||||||
|
|
||||||
|
### Using Vundle
|
||||||
|
|
||||||
|
Add these lines to the `.vimrc`:
|
||||||
|
|
||||||
|
|
||||||
|
Plugin 'junegunn/fzf'
|
||||||
|
Plugin 'git@github.com:papis/papis-vim.git'
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
The `:Papis` command will open a search window for your bibliographic database. `Enter` command will insert citation for the selected record in the current buffer.
|
||||||
|
|
||||||
|
## Configuration
|
42
plugin/papis.vim
Normal file
42
plugin/papis.vim
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
function! s:yank_to_register(data)
|
||||||
|
let @" = a:data
|
||||||
|
silent! let @* = a:data
|
||||||
|
silent! let @+ = a:data
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! s:handler(a)
|
||||||
|
let lines = a:a
|
||||||
|
if lines == [] || lines == ['','','']
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
" Expect at least 2 elements, `query` and `keypress`, which may be empty
|
||||||
|
" strings.
|
||||||
|
let query = lines[0]
|
||||||
|
let keypress = lines[1]
|
||||||
|
let cmd = "normal a"
|
||||||
|
let pat = '@\v(.{-})$'
|
||||||
|
" it is possible to yank the doc id using the ctrl-y keypress
|
||||||
|
if keypress ==? "ctrl-y"
|
||||||
|
let hashes = join(filter(map(lines[2:], 'matchlist(v:val, pat)[1]'), 'len(v:val)'), "\n")
|
||||||
|
return s:yank_to_register(hashes)
|
||||||
|
" this will insert \cite{id} command for all selected citations
|
||||||
|
else
|
||||||
|
let citations = lines[2:]
|
||||||
|
let candidates = []
|
||||||
|
for line in citations
|
||||||
|
let id = matchlist(line, pat)[1]
|
||||||
|
call add(candidates, "\\cite{". id . "}")
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
|
for candidate in candidates
|
||||||
|
execute join([cmd, candidate])
|
||||||
|
endfor
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
command! -bang -nargs=* Papis
|
||||||
|
\ call fzf#run(fzf#wrap({'source': 'papis list <args> --format "{doc[author]}: {doc[title]} @{doc[ref]}"', 'sink*': function('<sid>handler'), 'options': '--multi --expect=ctrl-y --print-query'}))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user