Vim can use a keywords file(s) for completion. I setup two with the help of the biblatex cheatsheet (PDF):
(For the contents of these two files hosted here on this site rather than remotely, see below.)
Now, in my session I have to declare those files for use with the completion
:set dictionary=~/.vim/kwd/biber_entries.dict
:set dictionary+=~/.vim/kwd/biber_fields.dict
Note that I made my test with the at sign in my entries file, but Vim
doesn't consider symbols here, unless it's tell (not tested and usable so)
to do so?
There's no way to put comments either, words after #
or "
are read too.
:set iskeyword+=@
Once the dictionaries
declared,
we're ready to complete based on them, after triggering a ^x
^k.
If happy with the files and that completion, add it permanently in your
~/.vimrc
but only for Bib files and make the setting local in order to
not disturb the other buffers.
au FileType bib execute 'setlocal dict+=~/.vim/kwd/biber_entries.dict,~/.vim/kwd/biber_fields.dict'
au BufNewFile,BufRead *.bib execute 'let &l:dictionary .= "," . tr(expand("~/.vim/kwd/biber_*.dict"), "\n", ",")'
There's still one annoyance: continuously switching to dictionary completion
sub mode. By default, ^n and ^p, unless the
appropriate ^x switch, Vim scans: the current buffer (.
),
buffers from other windows (w
), other loaded buffers that are in the
buffer list (b
), the unloaded buffers that are in the buffer list (u
),
then do tag completion (t
). Let's change it to always use our words list
first, then the current buffer:
:set complete=k,.
Now, we have homemade Bib files keywords completion, but also any
word/name,
and even line
already there. (full line still require ^x^l and I
cannot found how to add that in the option.) Also, when pleased with that
option value,
save it to the ~/.vimrc
and still ensure it's local. Good news, both
actions (defining desired completions and lookup files) can be done in one
step:
" also make the following fileType dependent
complete=k~/.vim/kwd/biber_entries.dict,k~/.vim/kwd/biber_fields.dict,.
Some people may prefer the use of ~/.vim/after/ftplugin/bib.vim
which is
always associated to that file type (hence easier to write: this file is
triggered like an autocmd fileType
, the cons is that there're more to
backup and restore.) As I don't use vimtex
, I don't know which method is
more compatible with its
behaviour.
Last notes.
- Entries type may not be needed because you use
vim-snippets
which
let you define nice input templates, just add yours for Bib files. I'm
also thinking to use such plugin, but for now I'm using abbreviations…
- There's no need to have two different files and it may be better to
have one global per file type… I did split because I feel more comfortable
working in smaller files.
- For switching between completion methods easily I'm planning to use
finally
mucomplete
plugin.
To be followed.
Here are the content of the .dict
files linked above
First, biber_entries.dict
:
article
periodical
suppperiodical
inbook
suppbook
bookinbook
book
mvbook
incollection
suppcollection
collection
mvcollection
inproceedings
proceedings
mvproceedings
inreference
reference
mvreference
manual
report
patent
thesis
online
booklet
unpublished
misc
set
xdata
Second, biber_fields.dict
:
author shortauthor
bookauthor
editor shorteditor
editora editorb editorc
afterword
annotator
commentator
forward
introduction
translator
holder
institution
organization
publisher origpublisher
title titleaddon origtitle shorttitle subtitle
indextitle
booktitle booktitleaddon subbooktitle
maintitle maintitleaddon submaintitle
journaltitle subjournaltitle
issuetitle subissuetitle
eventtitle eventtitleaddon
reprinttitle
series shortseries
volume
number
part
issue
volumes
edition
version
pubstate
pages
pagetotal
pagination bookpagination
date origdate
eventdate
urldate
location origlocation
venue
url
doi
eid
eprint
eprinttype
type
entrysubtype
addendum
note
howpublished
language origlanguage
isan
isbn
ismn
isrn
iswc
abstract
annotation
file
library
related
relatedtype
relatedstring
entryset
crossref
xref
xdata
langid
langidopts
gender
presort
sortkey
sortname
sortshorthand
sorttitle
indexsorttitle
sortyear
execute
keywords
options
ids