Saturday, August 22, 2009

Re: goto line depending on exit code of filter

On Aug 22, 5:53 am, bill lam <cbill....@gmail.com> wrote:
> On Sat, 22 Aug 2009, Jürgen Krämer wrote:
> > have a look at
>
> >   :help v:shell_error
>
> > This variable holds the result of the last shell command.
>
> Thanks for help. Excuse me for being dense. How to write a vimscript
> command to jump to line number v:shell_error?
>
> :if v:shell_error do.
> :  (jump to the error line)
> :else
> :  (jump to the previous current line)
> :end
>

I'm not sure where you get the error line number from, but once you
have it, Vim's if syntax is if...elseif...else...endif and is
otherwise just as you have written (without the "do").

You can jump to a line number in variable foo with :exec foo

This is because :5 will go to line 5, :10 will go to line 10, etc., so
"exec foo" will execute the value of variable "foo" as an ex command.
If foo contains the line number, you will jump there.

You could contain all this in a function with

function Myfunc
...
endfunction

and then :call Myfunc() to execute the script.

Finally, you could create your own custom command or mapping to call
it for you:

:command Mycommand call Myfunc()
:nnoremap <F10> :call Myfunc()<CR>

It is also possible to call it automatically whenever you do a filter
with

autocmd ShellFilterPost * call Myfunc()

but that would run on EVERY filter, not just this one, so I'm not sure
I'd recommend that.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

No comments: