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

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



Hi Richard,

2011/5/10 Richard Hartmann <richih.mailinglist@xxxxxxxxx>:
> I would like to be able to do the following, but I am stuck. Every
> pair of lines is what I would execute and what it would be transferred
> to. I am assuming that every file "name" (i.e. including colons etc) I
> am running Vim on does not exist. If it exists, it should be opened
> instead of magic happening. "foo" exists while "foo:" etc do not.
>
> vim foo:
> vim foo
>
> vim foo:bar
> vim foo
>
> vim foo:123
> vim foo +123
>
> vim foo:123:
> vim foo +123
>
> vim foo:123:bar
> vim foo +123
>
> Ideally, the same would happen for vimdiff. And yes, vimdiff heeds
> only one +n and the last one on the command line wins. That's fine.
>
>
> I am pretty sure this is trivial to do in zsh, but as I said I am at a
> loss as to how..

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
}

?

Best regards,

-- 
Jérémie



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