To execute the mapping silently, without the command appearing in the command-line, you should use the
<silent> modifier to
To check that the file exists, you can use the
You'll have to generate the PDF filename within Vim, but that shouldn't be hard, by using the additional
:r modifier to remove the extension. You'll also need
expand() to perform that expansion.
It's easier to use a separate function for the action, so you don't need to escape so many special characters.
One more note is that for a filetype mapping, you probably want to create a local mapping on the buffers with TeX files only. You might also want to use the
When running the external shell command, you'll want to use
shellescape() to ensure the file name is safe and that you can properly handle paths with spaces.
Putting it all together:
function! OpenPdf() abort
let fname = expand('%:p:r').'.pdf'
execute 'silent !open '.shellescape(fname, 1)
echomsg 'No pdf file "'.fname.'"'
au FileType tex nnoremap <buffer> <silent> <LocalLeader>p :<C-U>call OpenPdf()<CR>