patrickdavey
patrickdavey

Reputation: 2076

In vim ex mode, what does @% do?

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!

Upvotes: 1

Views: 303

Answers (1)

romainl
romainl

Reputation: 196466

@% 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.

Upvotes: 4

Related Questions