[ros-users] Vim plugin for ROS

Michael Styer michael at styer.net
Wed Jul 28 19:16:11 UTC 2010


Hello all,

Not sure how many other ROS programmers use Vim as their primary
development environment, but I do, so I've started writing a Vim plugin
for ROS. Currently I've only implemented the roscd function from rosbash
because that was specifically the feature I wanted to have, but I
thought I'd share it with the community at this stage anyway to get
feedback and see if anyone else has done anything similar.

My current version is attached -- it's basically a direct port of the
rosbash version. No tab completion, but that's next on the "roadmap".

Drop it in ~/.vim/plugin and restart vim, and you should be able to
use :Roscd <dir> just like you can with rosbash (except note the capital
R). Any and all feedback is welcomed and appreciated.

Mike

-------------- next part --------------
" Vim global plugin for working with ROS
" Last Change:  2010 Jul 27
" Maintainer:   Michael Styer <michael at styer.net>

" Helper commands
function! s:RosDecodePath(path)
    let rosname = ""
    let reldir = ""
    let rosdir = ""
    let last = ""

    if match(a:path,'\v.+/.*') == -1
        let rosname = a:path
    else
        let result = matchlist(a:path,'\v^([^/]+)(/.{-})([^/]*)$')
        let rosname = result[1]
        let reldir =  result[2]
        let last =    result[3]
    endif

    let rosdir = s:RosLocationFind(rosname)
    let rosvals = [rosname, rosdir, reldir, last]
    return rosvals
endfunction

function! s:RosLocationFind(name)
    if $ROS_LOCATIONS != ""
        let loc_dict = {}
        for p in split($ROS_LOCATIONS,':')
            let pair = split(p, '=')
            let loc_dict[pair[0]] = pair[1]
        endfor
        if has_key(loc_dict,a:name)
            return loc_dict[a:name]
        endif
    endif

    if a:name == 'log'
        return $ROS_ROOT . "/bin/roslaunch-logs"
    elseif a:name == 'test_results'
        return $ROS_ROOT . "/test/rostest/bin/test-results-dir"
    endif

    let cmd = "export ROS_CACHE_TIMEOUT=-1.0 && rospack find " . a:name . " 2> /dev/null"
    let location = system(cmd)
    if v:shell_error != 0
        let cmd = "export ROS_CACHE_TIMEOUT=-1.0 && rosstack find " . a:name . " 2> /dev/null"
        let location = system(cmd)
    endif
    let location = substitute(location, "\n", "", "")
    return location
endfunction

" Top level commands
function! s:RosChangeDir(...)
    if a:0 == 0 || a:1 == ""
        lcd $ROS_ROOT
        return
    endif

    let rosvals = s:RosDecodePath(a:1)
    if rosvals[1] == ""
        echo "No such package: " . a:1
        return
    else
        let dir = rosvals[1] . rosvals[2] . rosvals[3]
        echo dir
        execute "lcd " . dir
    endif

endfunction

function! Rosed(pack, dir)
    echo "rosed"
endfunction

if !exists(":Roscd")
    command -nargs=? Roscd :call s:RosChangeDir(<f-args>)
endif



More information about the ros-users mailing list