I'm using Vim to write LaTeX on my Mac.

I could make a shortcut to execute pdflatex (it should be possible right?) and see the result on Preview. But it steals the focus when it updates to the new pdf, so it's quite annoying.

What do you suggest?

  • Does using :!pdflatex not work? That way you'll be able to execute the command then jump right back to your buffer.
    – Patrick
    May 26, 2017 at 15:23

3 Answers 3


When I write my Latex Documents I use always this small Makefile i've written. You can execute it the same way Patrick proposed it. (:!make c or :!make C or :!make pdf or :!make clean)

EXTENSIONS:=aux bbl blg cut dvi log out pdfsync ps synctex.gz tdo toc tex~ backup xmpi fls fdb_latexmk lof lot



default: pdf

    latexmk -pdf -jobname="$(PDF_NAME)" -shell-escape $(MAIN)

    latexmk -c $(MAIN)
    @for i in $(EXTENSIONS); \
    do \
        for file in `find . -name "*.$$i"`; do rm $$file; done; \
    done; \
    rm -rf _minted*

    make clean; \
    rm *.pdf

    make C; \
    make; \
    make clean;

On Ubuntu at least, evince foo.pdf &, started from the terminal, refreshes its display when it notices that foo.pdf has changed, without stealing focus. From within vi, :!make then does what you want. I don't have a Mac to play with, but some Mac pdf viewer may behave like this too.


The best way I've found so far is to type :!pdflatex [insert rest of command here] within vim to compile it, then view it with Skim. If you change the file while it is open in Skim, Skim will ask if you want to display the current file automatically once, so choose the affirmative option, and then you can watch it update in the background each time you compile. Also, don't forget that :!! will repeat the last shell command, so you don't have to type out the compile command each time.

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.