konze
konze

Reputation: 893

Using '#' in bash command in .vimrc

I'd like to create a new command which compiles my current *.tex file and shows in an pdf viewer (I'm using OSX due to this I use Preview). Here is my attempt:

autocmd BufReadPost,BufWritePost *.tex nmap <Leader>b :!TEMP=% && PDF=${TEMP:0: ${#TEMP}-4 } && echo $TEMP && "/usr/texbin/pdflatex" -synctex=1 -interaction=nonstopmode % && open $PDF && unset TEMP PDF<CR>

TEMP is the file name of mit *.tex file.

PDF is the file name of my *.pdf.

However when I execute this I get the following error message:

499: Empty file name for '%' or '#', only works with ":p:h"

Is there a different method to shorten a string without using '#'?

Solution:

autocmd BufReadPost,BufWritePost *.tex nmap <Leader>b :!PDF="%<.pdf" && "/usr/texbin/pdflatex" -synctex=1 -interaction=nonstopmode "%" && open "$PDF" && unset PDF<CR>

Upvotes: 1

Views: 87

Answers (1)

Dan Hulme
Dan Hulme

Reputation: 15280

Why not use the error message's suggestion and set PDF in Vimscript instead of in shell? Replace

PDF=${TEMP:0: ${#TEMP}-4 }

with

PDF=%<

or even

PDF=%<.pdf

to give it the proper extension.

Upvotes: 3

Related Questions