Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Context

I currently write research articles in LaTeX using Vim. I have bibtex keys in my articles like \cite{smith2000sometopic} and I have corresponding pdf versions of most articles in a subfolder of ~/lib e.g., ~/lib/topica/smith2000sometopic.pdf.

Aim

I'd like to be able to press a key in Vim when my cursor is over a bibtex key that:

  1. extracts the bibtex-key under the cursor
  2. performs a search for bibtex-key.pdf
  3. if the file is found, opens the file in a pdf viewer
  4. If the file is not found, indicate that this is the case

Question

  • Has anyone already done something like this?
  • Are there any examples that would be useful to study?

Initial thoughts

I thought I could use something like:

 gnome-open `find ~/lib/ -iname "smith2000sometopic.pdf" | head -1`

and then experiment with some Vimscript to fine tune the interaction; but if anyone has any examples or suggestions, that would be most appreciated.

share|improve this question
add comment

1 Answer

Perhaps, I should have persisted a little longer before posting, but any suggestions for improvement are still more than welcome.

In the end I found this documentation useful from vimtips.

This was the Vim function I wrote:

function! OpenBibtexPDF()
    let s:word = expand("<cword>")
    let s:cmd = "!gnome-open `find ~/lib/ -iname '" . s:word . ".pdf' | head -1`"
    execute s:cmd
endfunction 
map <silent> <leader>bb :call OpenBibtexPDF()<cr>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.