I want to be able to open the results of the program I am editing from vim and found an easy way to do this
I added this to my .vimrc and now Ctrl F9 will open up the pdf file generated from my latex document (It won't compile my latex document of course)
In case you are lost, 'au BufEnter' makes sure this shortcut is only bound when the filename ends in tex, which is the extension for latex documents. % will output the current file name, while %:r will give you the filename minus the extension.
The problem with this is I must close this document before I get vim back, so a quick solution is
This will do two things, open the pdf as a background process and also pipe the output to /dev/null, this way i will not have the output overwriting my vim terminal.
This seems to work perfect until I make vim a background process. When that happens the pdf freezes waiting for vim to return to the foreground.
This next command should work, but it doesn't immediately because of vim. Vim does not execute its commands using an interactive terminal. So this next command will have the same effect as the previous one at first.
In order to make the above line work we need to add this next bit to .vimrc
:au BufEnter *.tex map <C-F9> :!evince %:r.pdf <CR>
I added this to my .vimrc and now Ctrl F9 will open up the pdf file generated from my latex document (It won't compile my latex document of course)
In case you are lost, 'au BufEnter' makes sure this shortcut is only bound when the filename ends in tex, which is the extension for latex documents. % will output the current file name, while %:r will give you the filename minus the extension.
The problem with this is I must close this document before I get vim back, so a quick solution is
:au BufEnter *.tex map <C-F9> :!evince %:r.pdf > /dev/null 2>&1 &<CR>
This will do two things, open the pdf as a background process and also pipe the output to /dev/null, this way i will not have the output overwriting my vim terminal.
This seems to work perfect until I make vim a background process. When that happens the pdf freezes waiting for vim to return to the foreground.
This next command should work, but it doesn't immediately because of vim. Vim does not execute its commands using an interactive terminal. So this next command will have the same effect as the previous one at first.
:au BufEnter *.tex map <C-F9> :!evince %:r.pdf & disown<CR>
In order to make the above line work we need to add this next bit to .vimrc
set shellcmdflag=-ic
When setting the shellcmdflag to -ic and running non gui processes, you will have to type exit or fg after the program finishes to get back into vim.
ReplyDeleteThe best solution so far is to add ' && exit' to the end of each shortcut that executes non gui programs.