Search this site


Metadata

Articles

Projects

Presentations

Neat vim/screen trick.

For some time I've been wanting to be able to pop open a small split-pane in vim to run simple commands like, oh.. I don't know.. javac and such. Just for temporary, quick shell access.
Tonight, as I was browsing through the screen manpage, I saw that screen allowed you to split the window into different regions. Using this and a quick vim key mapping, I was able to do it without much trouble!

The vim keymapping:

map \s :silent !screener.sh<CR>
Contents of screener.sh
screen -X split
screen -X focus down
screen -X screen sh -c "cd $PWD; $SHELL; screen -X remove"

Thanks to screen being smart, you don't have to specify what screen session to send these commands to, which made it 10000% easier, as we don't have to bother trying to figure out which screen session is running vim. You could optionally add a :!screen -X resize <whatever> before to resize the lower frame to a specific size. See the screen manpage for more information on how to use screen -X and the resize command.

The results of hitting \s in vim can be found in the screenshot on the right. After logging out of that shell, the newly-split screen disappears and returns you to your original, full-screen vim.