Using MacVim 8.1.1722, if I print a buffer, it opens a PDF in Preview.app. I want to open the PDF in Google Chrome instead. So I changed the file association so open foo.pdf opens Google Chrome not Preview.app. And then I set my printexpr in MacVIM as follows:

se printexpr=system('ps2pdf\ '.v:fname_in.'\ '.v:fname_in.'.pdf\ &&\ open\ '.v:fname_in.'.pdf')\ +\ v:shell_error

And using the above printexpr, it does what I want.

The problem is when I try to persist the above setting in $HOME/.vimrc. It doesn't take effect, upon restarting MacVim, printexpr still has the default value of

se printexpr=system('open\ '-a\ Preview\ '.v:fname_in)\ +\ v:shell_error

But if I set other related options, such as se popt, in $HOME/.vimrc, it does take effect. Also, the command line vim (VIM 7.4 shipped by Apple as part of macOS 10.12.6) does pick up the printexpr from that file.

So, how do I get my printexpr setting to persist?

1 Answer 1


I worked it out myself. I need to add the setting to $HOME/.gvimrc as well.

If the setting is in $HOME/.vimrc, then MacVim overrides it. If the setting is in $HOME/.gvimrc, then MacVim doesn't override it.

  • 1
    Simon, great you figured it out. Although this is surprising. To find out were the setting is overridden, remove it from .gvimrc and restart Vim. Then execute verbose set printexpr. This will display were printexpr was last set.
    – Ralf
    Aug 21, 2019 at 6:21
  • 1
    It says: Last set from /Applications/MacVim.app/Contents/Resources/vim/gvimrc line 37. Looking in that file, I see a set printexpr= on that line, along with a comment above it explaining that it is to "Send print jobs to Preview.app" Aug 21, 2019 at 6:53
  • @Ralf somethings are reset post-vimrc by the gui modes.
    – D. Ben Knoble
    Aug 21, 2019 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.