Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Substituting grep (and other) output to open files in Vim



2011/5/10 Jérémie Roquet <arkanosis@xxxxxxxxx>
> Something like
> vim() {
>  if test -r $1; then
>    command vim $1
>  else
>    args=(${(s.:.)1})
>    [[ $args[2] = <-> ]] && command vim $args[1] +$args[2] || command
> vim $args[1]
>  fi
> }

Nice.  Let's improve that so that it is possible to specify multiple
files and/or options and files (though we don't give anything but a
single arg special treatment) and also to avoid a "parameter not set"
error for folks that like to run interactively with "setopt no_unset":

vim() {
    if test $# != 1 -o -r $1; then
        command vim "${@}"
    else
        local args
        args=(${(s.:.)1})
        [[ $#args == 2 && $args[2] == <-> ]] \
            && command vim $args[1] +$args[2] \
            || command vim $args[1]
    fi
}

..wayne..



Messages sorted by: Reverse Date, Date, Thread, Author