tags:

views:

39

answers:

3

Hi,

I'm trying to open a PDF file from Vim using the commands

let openpdfname = "!open " . expand("%:t:r") . ".pdf"
map <F6> :silent execute openpdfname<CR> | redraw!

The PDF opens up in Preview and all is well, except that the Vim screen is not repainted. I use vim 7.2.108 (shipped standard with OSX 10.6) from the terminal window. I tried removing my ~/.vimrc entirely to try and determine the cause, with no luck.

Hitting Ctrl-L repaints the screen, but I thought 'redraw!' would have the same effect!?

Thanks for any hints!

+1  A: 

Move <CR> to the end of mapping. You are trying to execute redraw after you exited command mode. Of course, it does not work.

ZyX
Thanks, but simply moving <CR> to the end causes Vim to complain that there are "trailing characters". Sorry for not being fluent in Vim mapping syntax.
Dominique
@Dominique Yes, I forgot that you need to escape `|` in a map. Correct syntax is `noremap <F6> :silent execute openpdfname \| redraw!<CR>`: without backslash it is similar to two commands: `map` and `redraw`, while you need a single `map`. When you move `<CR>` to the end it complains about trailing characters to `redraw!` which does not take any arguments..
ZyX
A: 

The correct syntax that does what I expect is:

map <F6> :silent execute openpdfname<CR>:redraw!<CR>
Dominique
A: 

Try this:

map <silent> <F6> :silent execute openpdfname<CR>
Virasak