Entries in the Category “vim”

One vim server per desktop

written by nicoe, on Jan 27, 2011 9:14:00 PM.

I usually organize my desktop 'semantically'. The first desktop is where I do my main development, the second one is where I test those developments, the third one is used for my tests in bpython or when I need to write some little examples. The last desktops is where I have my luakit windows and the next to last one is where I have my gajim, xchat and mutt windows. The five other desktops are usually empty but are there in case of need.

And here is what my typical desktop looks like:

/static/nicoe/thumb_desktop_20110127.png

One thing that annoy the hell out of me is the fact that I cannot open a specific file in my already running vim from one of the command line. So today, I finally stop complaining about that and I read about the remote option of vim.

So here is my script that will create a server per desktop and if a server is already running on this desktop than it will connect to it and open the file into it.

#!/bin/sh
if test -n "$DISPLAY"; then
    desktop="SERVER$(wmctrl -d | grep '\*' | cut -f 1 -d ' ')"
    vim --serverlist | grep $desktop
    if [ $? -eq 1 ]
    then
        urxvtcd +sb -geometry 80x57 -e vim --servername $desktop $* >> /dev/null &
    else
        vim --servername $desktop --remote $*
    fi
else
    vim $*
fi

The trickier part was finding the wmctrl tool which is a nice utility to interact through the command line with EWMH/NetWM compatible X Window managers (and thus with my the greatest WM of all time : openbox ;)).