bash - Use VIM to pass options to PDF reader
2013-11
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!
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.
How does one disable swap files for VIM via .vimrc
?
set nobackup
set nowritebackup
set noswapfile
Throw this into your .vimrc
:
set noswapfile
I would not disable swap files completely because they are used for recovery if vim crashes.
Instead, put them into a temp folder so that they are not scattered all over:
if has("win32")
set directory=c:\\tmp,c:\\temp
elseif has("unix")
set directory=/tmp
endif
start vim with the "-n" argument:
vim -n <file>