diff options
| -rw-r--r-- | vim/.latexmkrc | 25 | ||||
| -rw-r--r-- | vim/.vimrc | 19 | 
2 files changed, 43 insertions, 1 deletions
| diff --git a/vim/.latexmkrc b/vim/.latexmkrc index ce212c3..2d07232 100644 --- a/vim/.latexmkrc +++ b/vim/.latexmkrc @@ -1,6 +1,29 @@ +# vim: ft=perl:  $pdf_mode = 1; -$pdf_previewer = 'SERVER=`md5sum %T`; zathura -x "vim --servername \'$SERVER\' --remote-tab +%{line} %{input}" %S & urxvt -e vim --servername "$SERVER" %T'; +# With the following, `latexmk -pvc jobname.tex` opens a zathura instance for +# the generated PDF alongside an nvim editor, and sets up synctex from zathura +# to vim. + +# create a vim rpc socket based on the filename +$pdf_previewer = 'SERVER=/tmp/vim-latexmk-`md5sum %T | cut -d\' \' -f1`;'; + +# zathura for viewing +$pdf_previewer .= 'zathura'; +# -x for synctex: connect to the rpc socket, switch to the file and jump to the line +$pdf_previewer .= ' -x "nvim --headless --cmd'; +$pdf_previewer .= ' \'let skt=sockconnect(\\"pipe\\",\\"$SERVER\\",{\\"rpc\\":1})'; +$pdf_previewer .= ' | call rpcrequest(skt,\\"nvim_command\\",\\"SwitchToFileOrOpen %{input}\\")'; +$pdf_previewer .= ' | call rpcrequest(skt,\\"nvim_command\\",\\"%{line}\\")'; +# mysteriously, we need `cd .` to fix the file name in the tabline +$pdf_previewer .= ' | call rpcrequest(skt,\\"nvim_command\\",\\"cd .\\")'; +$pdf_previewer .= ' | call chanclose(skt)'; +$pdf_previewer .= ' | quit\'"'; +# final argument for zathura is the PDF +$pdf_previewer .= ' %S &'; + +# nvim for editing; start up the server as part of the command line +$pdf_previewer .= 'urxvt -e nvim --cmd "let g:server_name = serverstart(\'$SERVER\')" %T';  push @extra_pdflatex_options, '-synctex=1' ;  push @extra_pdflatex_options, '-halt-on-error' ; @@ -174,6 +174,25 @@ augroup gitgutter  	autocmd gitgutter BufEnter * call s:reset_gitgutter_highlights()  augroup END +" Switch to a window that has a buffer open, or open a new window if no window +" exists for that filename. +function! s:switch_to_file_or_open(filename, in_tab) +	let id=bufwinid('^' . a:filename . '$') +	if id < 0 +		if a:in_tab +			tabnew +		else +			new +		endif +		exe 'edit ' . fnameescape(a:filename) +	else +		call win_gotoid(id) +	endif +endfunction + +" NB: this is used in ~/.latexmkrc, don't change without checking there +command! -nargs=1 -complete=file SwitchToFileOrOpen call s:switch_to_file_or_open(<f-args>, 1) +  " Move through long lines as they were short multiple lines  map <down> gj  map <up> gk | 
