Created
September 27, 2011 19:13
-
-
Save derekwyatt/1245947 to your computer and use it in GitHub Desktop.
An example of integrating a simple shell script into Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" When I'm editing some LaTeX, I use PDF files to handle any inserted images and | |
" LaTeX has some difficulty lining them up right, so I explicitly state the | |
" viewport. To get the bounding box from the PDF file, I have a script called | |
" 'getbb'. This function is /very/ specific to my needs. It pulls the filename | |
" from the current line, which always looks something like this: | |
" | |
" \includegraphics[scale=0.5, viewport = 40 39 703 153]{target/filename.pdf} | |
" | |
" Pulls out the filename (i.e. target/filename.pdf), runs 'getbb' on that and | |
" inserts the output back overtop of the "viewport = 40 39 703 153". | |
" | |
" The couple of mappings make everything real easy to use. | |
function! UpdateBoundingBox() | |
let l = getline('.') | |
let f = substitute(l, '.*{\(.*\)}.*$', '\1', '') | |
if f =~? '[^/]\+/[^/]\+\.pdf' | |
if filereadable('getbb') | |
let bb = system('getbb ' . f) | |
let bb = substitute(bb, '.$', '', '') | |
:s/\zsviewport.*\ze\]/\=bb/ | |
else | |
echoerr "Can't find getbb... are you in the right directory?" | |
endif | |
else | |
echoerr "Couldn't get a pdf file from the current line." | |
endif | |
endfunction | |
nmap <buffer> ,bb :call UpdateBoundingBox()<cr> | |
nmap <buffer> ,abb :g/includegraphics.*viewport/execute ':call UpdateBoundingBox()'<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment