2

I have a BASH script that recompiles a latex document and reopens it up using my PDF reader when the buffer is written back. The command in my '.vimrc' looks like this:

autocmd BufWritePost *.tex !~/scripts/latex_update.sh %

This works well, but the reader always opens the PDF to the first page. This is inconvenient since I have to scroll to look at the changes I just made. I would like to set a VIM variable called 'page_num' and pass it as a second argument to my script.

I have tried this in VIM:

:let g:page_num=2

I then changed my 'autocmd' to:

 autocmd BufWritePost *.tex !~/scripts/latex_update.sh % g:page_num

However, the global 'page_num' variable does not get replaced with its value. How can I get VIM to pass the value of 'page_num'?

Thanks!

0

1 Answer 1

2

Using :exe to expand the variable before executing the rest of the command should work:

autocmd BufWritePost *.txt exe '!~/scripts/latex_update.sh %' g:page_num

Note that you don't need to concatenate (the . operator) or put a space before g:page_num since :exe does that as part of its argument expansion.

1
  • You should use shellescape(expand('%')) instead just % just in case the file has spaces or some other weird character.
    – FDinoff
    Jul 18, 2013 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .