aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorCamil Staps2023-01-15 20:48:59 +0100
committerCamil Staps2023-01-15 20:48:59 +0100
commit04cbdb51a0e02619e0ca8bc717f1a599560befa5 (patch)
treeffd425a9fd168b5ad9c8a1a7c4a9eb225a6b0642 /vim
parentAdd JetBrains Mono font (diff)
Improve synctex; when clicking in the PDF focus the vim window
Diffstat (limited to 'vim')
-rw-r--r--vim/.latexmkrc5
-rw-r--r--vim/.vim/after/ftplugin/tex.vim13
2 files changed, 12 insertions, 6 deletions
diff --git a/vim/.latexmkrc b/vim/.latexmkrc
index 8ee0b76..c4ec9ee 100644
--- a/vim/.latexmkrc
+++ b/vim/.latexmkrc
@@ -13,10 +13,7 @@ $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\\",\\"tab drop %{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 rpcrequest(skt,\\"nvim_command\\",\\"call SyncPDFToTeX(\\\\\\"%{input}\\\\\\",\\\\\\"%{line}\\\\\\")\\")';
$pdf_previewer .= ' | call chanclose(skt)';
$pdf_previewer .= ' | quit\'"';
# final argument for zathura is the PDF
diff --git a/vim/.vim/after/ftplugin/tex.vim b/vim/.vim/after/ftplugin/tex.vim
index de2ec0b..6de2aea 100644
--- a/vim/.vim/after/ftplugin/tex.vim
+++ b/vim/.vim/after/ftplugin/tex.vim
@@ -1,10 +1,19 @@
setlocal spell spelllang=en_gb
setlocal tabstop=2 shiftwidth=2
-function! Synctex()
+function! SyncTeXToPDF()
call system('zathura --synctex-forward ' .
\ line('.') . ':' . col('.') . ':' . shellescape(bufname('%')) . ' ' .
\ shellescape(g:synctex_zathura_pdf_filename))
endfunction
-map <C-T> :call Synctex()<CR>
+function! g:SyncPDFToTeX(input, line)
+ " Focus the window vim is running in.
+ exe "silent !i3-msg '[id=\"" . environ()['WINDOWID'] . "\"] focus'"
+ " Open the file name and jump to the right line.
+ " Mysteriously, we need `cd .` to fix the file name in the tabline.
+ " Putting this in one `exe` seems to reduce flickering.
+ exe 'tab drop ' . a:input . ' | silent ' . a:line . ' | silent cd .'
+endfunction
+
+map <C-T> :call SyncTeXToPDF()<CR>