使用 VIM/GVIM 编辑时,如何从包含文件中对使用 Okular 打开的 PDF 文件进行正向搜索

使用 VIM/GVIM 编辑时,如何从包含文件中对使用 Okular 打开的 PDF 文件进行正向搜索

我正在使用 vim 来编辑我的 tex 文件,并使用 latex suite 作为插件来编译我的 tex 源并使用 Okular pdf 查看器来查看它们。

在 Okular 设置中设置以下内容可使反向搜索完美运行

gvim --servername GVIM --remote +%l %f

但是在网上查找并尝试了不同的方法,让前向搜索在带有 latex suite 的 vim 中工作后,前向搜索在 vim 中仍然只对我部分起作用。我只能在\ls主 tex 文件中进行前向搜索。如果我\ls在包含或输入文件中执行此操作,Okular 会抱怨它找不到该包含/输入文件的特定 pdf,这是真的,因为只有主 tex 文件才有编译的 pdf。

我还尝试了一个自定义函数,它是我在 TeXExchange 上对类似问题的回答中找到的:https://tex.stackexchange.com/a/2947/2031但是通过此命令传递给 Okular 的路径只是主 pdf 和 tex 文件路径的串联。

以下是我的 .vimrc 中与此问题相关的当前设置:

let g:Tex_CompileRule_pdf = 'pdflatex -synctex=1 -src-specials -interaction=nonstopmode $*'
let g:Tex_ViewRule_pdf = 'okular --unique'
function! SyncTexForward()
     let execstr = "silent !okular --unique %:p:r.pdf\#src:".line(".")."%:p &"
     exec execstr
endfunction
nmap <Leader>f :call SyncTexForward()<CR>

答案1

我遇到了完全相同的问题。修改函数以传递正确的路径至少对我来说是有效的。以下是代码:

function! SyncTexForward()
let s:syncfile = fnamemodify(fnameescape(Tex_GetMainFileName()), ":r").".pdf"
let execstr = "silent !okular --unique ".s:syncfile."\\#src:".line(".").expand("%\:p").' &'
exec execstr
endfunction
nnoremap <Leader>f :call SyncTexForward()<CR>

相关内容