You could try using a filename-modifier like :r
or a combination of several like :t:r
.
:t
should allow you to get the tail of the path, that is just the last element in the path (baz
in /foo/bar/baz
). And :r
the root of the path, the path without the extension of the last item (/foo/bar/baz
in /foo/bar/baz.c
). So you could try one of the 2 following commands:
map <F10> :!pdflatex % && start %:r.pdf<CR>
map <F10> :!pdflatex % && start %:t:r.pdf<CR>
If your filenames may contain special characters which you want to protect from the shell, you can use the function shellescape()
. But in this case you would also probably have to:
use the function expand()
to force the expansion of %
and %:r
before the call to shellescape()
,
build the mapping with a concatenation of strings to force the evaluation of the functions before sending the command to the shell,
- execute the result with the command
:execute
.
Maybe something like this:
map <F10> :execute '!pdflatex ' . shellescape(expand('%')) . ' && start ' . shellescape(expand('%:r') . '.pdf')<CR>
And if your filenames may contain special characters which you want to protect from Vim (like !
, %
and #
, because they have a special meaning on Vim's command-line), you can pass a 2nd non-zero argument to the shellescape()
function.
map <F10> :execute '!pdflatex ' . shellescape(expand('%'), 1) . ' && start ' . shellescape(expand('%:r') . '.pdf', 1)<CR>
For more information, see:
:help filename-modifiers
:help :execute
:help expand()
:help shellescape()
:r
or a combination of several like:t:r
.:t
should allow you to get the tail of the path, that is just the last element in the path (baz
in/foo/bar/baz
). And:r
the root of the path, the path without the extension of the last item (/foo/bar/baz
in/foo/bar/baz.c
). So you could try:!pdflatex % && start %:r.pdf
or!pdflatex % && start %:t:r.pdf
– saginaw Feb 8 '16 at 21:45\ll
) that starts latexmk in continuous compilation mode, which IMHO is a very convenient way of working with LaTeX documents. – Karl Yngve Lervåg Feb 8 '16 at 22:06start $(basename % .tex).pdf
– Steve Feb 9 '16 at 14:13