Tuesday, November 29, 2011

Vim Ubuntu and Clipboard

In Ubuntu on my system text copied in vim (even when selecting the +, or * register) isn't available for other programs. Also sometimes the text copied from other programs is also not available. This post helped me:

http://scribu.net/util/vim-and-the-ubuntu-clipboard.html

Or if you want to save time, just install this package

sudo apt-get install vim-gnome

Friday, November 25, 2011

Suspending Vim with Background Processes

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

: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