After some headaches I have synctex working between CLI vim (on osX terminal) and Skim, so I can give you an overview of my setup:
I use latexmk for compilation and following their suggestion my .latexmkrc file looks like
$pdf_previewer = 'open -a Skim';
$pdflatex = 'pdflatex -synctex=1 -interaction=nonstopmode';
@generated_exts = (@generated_exts, 'synctex.gz');
This may not be completely necessary for synctex use, but it lets me use simple commands in my .vimrc for compiling and viewing from a .tex document, e.g.:
nnoremap <leader>c :w<CR> :silent !latexmk -pdf -pv -halt-on-error % <CR> <C-L><CR>
I'm using Skim version 1.6.3, downloaded directly from their site.
Forward search (.tex/vim to .pdf/Skim) is pretty straightforward, just using a slightly modified command (again in my .vimrc) from the source you mentioned:
nnoremap <leader>f :w<CR>:silent !/Applications/Skim.app/Contents/SharedSupport/displayline <C-r>=line('.')<CR> %<.pdf<CR> <C-L><CR>
EDIT (2023-01-28): Forward search if you have a multi-file document is more complicated but I just worked this out so I'm adding for posterity. The above command searches for a pdf file matching the current .tex document name. If you are instead working with a master .tex file that utilizes include{} with sections/chapters, you'll have to specify the name of the output pdf and the current .tex section/chapter document in order to forward search. This answer gave me enough to go on as far as using the .synctex.gz file to automatically name the output pdf, and the forward search in my .vimrc looks like:
nnoremap <leader>f :silent !/Applications/Skim.app/Contents/SharedSupport/displayline <C-r>=line('.')<CR> <C-r>=substitute(glob("*synctex.gz"),"synctex.gz","pdf","")<CR> % <CR><C-L>
If you might be compiling documents that don't have .synctex.gz files, you can combine the approaches in an if statement:
nnoremap <leader>f
\ :if filereadable(glob("*.synctex.gz"))
\ <bar> silent !/Applications/Skim.app/Contents/SharedSupport/displayline <C-r>=line('.')<CR> <C-r>=substitute(glob("*synctex.gz"),"synctex.gz","pdf","")<CR> % <CR>
\ <bar> else
\ <bar> silent !/Applications/Skim.app/Contents/SharedSupport/displayline <C-r>=line('.')<CR> %<.pdf<CR>
\ <bar> endif <CR><C-L>
END EDIT (2023-01-28)
Reverse search (.pdf/Skim to .tex/vim) was a bit more tricky. I found that the native vim on my mac (version 8.0, High Sierra 10.13.6) does not have the --remote features, so I installed vim version 8.2 using macports and built with +huge +gtk2 +X11 +clientserver:
sudo port install vim +huge +gtk2 +X11 +clientserver
If you don't want/have macports (or homebrew, etc) or don't want to install another vim, you could probably upgrade your mac's native vim by building from source and including the necessary pieces, but I went this route because I like to leave the native stuff alone. Note that you will need X11 installed as well.
After that, I set the command in Skim (Skim > Preferences > Sync > PDF-Tex Sync support) to /opt/local/bin/vim
(the new vim I installed) and the options to --servername VIM --remote-silent +%line "%file"
. I found that if I open my .tex file in vim with the same command (/opt/local/bin/vim --servername VIM --remote-silent <file>
), then reverse search works from Skim, using Command+Shift+Click.
I'm really not sure why I have to specify the servername here, but it does seem necessary. For example, if I open vim without specifying the servername (or use a vim that is not built with remote support) this feature doesn't work. Skim also cannot open a new vim instance, so I have to already have opened the document (with the specified command). This setup works for me, but I think one could write a shell script that Skim calls, which looks for open vim instances and opens one correctly if none are found (similar to the source you cite, but actually functional for CLI vim). To make it a bit easier I did write a command in my .bashrc to specifically open .tex files for use with Skim:
lvim ()
{/opt/local/bin/vim --servername VIM --remote-silent "$1"}
So now I just open the .tex file I want from the terminal with $lvim <file>.tex
and open Skim either manually (open -a Skim <file>.pdf
) or from vim by compiling (<leader>c
) or forward searching (<leader>f
) and forward and reverse search features are good to go.
I wanted to lay it all out here because I haven't yet found a (working) description for pairing standard CLI vim with Skim via synctex. However, I should note that if you are just looking for some sort of vim/synctex/Skim combo on osX and aren't married to CLI vim, it is certainly easier to use macvim. I installed macvim with macports and used Skim's macvim preset and it immediately worked, including opening a new macvim instance when a reverse search was called and the .tex file was not open.