TeX - LaTeX Asked on May 3, 2021
When I call the command command ViewPdf !okular %:r.pdf
on Vim (in .vimrc), the terminal is blocked and I cannot continue writing my document.How can i tweake this vim command to open my pdfviewer and let me write the text in vim? I tried this options already:
command ViewPdf !okular %:r.pdf &
command ViewPdf !okular %:r.pdf & disown
command ViewPdf !okular %:r.pdf && disown
[Edit-1]: I don’t want to use plugins to do this. I have a pretty sh** machine so I want to avoid adding things to my runtime, if possible
[Edit-2]: my .vimrc file:
command ViewPdf execute "!okular %:r.pdf &" | redraw
command CompileXelatex !xelatex -interaction=nonstopmode %
command CompileLatex !latexmk -pdfxe %
The trick is to let the reader fork into the background silently and redraw in VIM:
:command ViewPdf execute "silent !okular %:r.pdf&" | redraw!
This uses execute
so that only the things in the quotes after the exclamation mark are passed to the shell and the | redraw!
is interpreted by VIM.
The redraw
might not always be necessary (I'm actually not sure when it really is), so instead just
:command ViewPdf silent !okular %:r.pdf&
might work as well.
Alternatively, you could as well solve this with a mapping, e.g.,
:nmap <leader>s :silent ! okular %:r.pdf&<cr> :redraw!<cr>
This will define the key combination <leader>s
to open okular for you in normal mode. <leader>
uses the key which is stored in mapleader
(by default a backslash, you can use :let mapleader = ","
to make it a comma instead for example).
Answered by Skillmon on May 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP