aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2021-06-15 14:41:37 +0200
committerCamil Staps2021-06-15 14:41:37 +0200
commit3d9c2336b24a17c5d80012abb2bfbc159a8b14db (patch)
tree23f4ffb556963d28540bad8bcbe585515e9782d7
parentAdd neovim aliases vi and vim (diff)
Fix synctex setup in .latexmkrc for neovim, which does not have --servername
-rw-r--r--vim/.latexmkrc25
-rw-r--r--vim/.vimrc19
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' ;
diff --git a/vim/.vimrc b/vim/.vimrc
index 4e25604..f37d803 100644
--- a/vim/.vimrc
+++ b/vim/.vimrc
@@ -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