I was writing a little vim leader mapping to convert a file in (GitHub flavoured markdown) to a pdf.
Both of these work, and seem to be functionally equivalent:
nnoremap <expr> <leader>pdf ':! pandoc -f markdown_github --latex-engine=xelatex ' . shellescape(@%,1). ' -o ' . shellescape(expand('%:r'), 1) . ".pdf \<cr>"
nnoremap <expr> <leader>pdf ':! pandoc -f markdown_github --latex-engine=xelatex ' . shellescape(expand('%'),1). ' -o ' . shellescape(expand('%:r'), 1) . ".pdf \<cr>"
I had the first one working (thanks Stack Overflow ;) but I didn't really understand the @%
in the first shellescape. So I replaced it with the expand('%')
which I "get" a bit more.
Can anyone explain the difference, or even where to go to look this up? I did read :help :@
but it talks about Execute the contents of register as an ex command
, which, doesn't seem to be what is happening here.
Any help / pointers would be great!
@%
is a register that contains the name of the file associated with the current buffer. It can be used like any other register, for example:
i<C-r>%
"%p
In your first example, shellescape()
expects a String as its first parameter and outputs a String. It happens so that the type of @%
is String so @%
can be used directly.