triggering macro on navigation to new line

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

triggering macro on navigation to new line

Ed Peschko
All,

I just found :set nolazyredraw, which is *very* nice in speeding up
user interaction time, and which helps immensely with my goal of a
quickfix-like editing mode (see the post that I made earlier), so the
only thing left is if there is a way to trigger an action when you go
to a new line, whether you:

1. search for a pattern
2. do :<lineno>
3. hit j or k, up-arrow, down-arrow

I suppose I could re-map each of these actions but IMO it would be a
lot cleaner if something universal existed. Does vim have something
like this?

thanks much again,

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CACQ%2BYcuekYV1NeOYOZfsZNyQFskUrGJu0%3DXsRFmeeA4y%2Bgfkvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: triggering macro on navigation to new line

Gary Johnson-4
On 2019-05-13, Ed Peschko wrote:

> All,
>
> I just found :set nolazyredraw, which is *very* nice in speeding up
> user interaction time, and which helps immensely with my goal of a
> quickfix-like editing mode (see the post that I made earlier), so the
> only thing left is if there is a way to trigger an action when you go
> to a new line, whether you:
>
> 1. search for a pattern
> 2. do :<lineno>
> 3. hit j or k, up-arrow, down-arrow
>
> I suppose I could re-map each of these actions but IMO it would be a
> lot cleaner if something universal existed. Does vim have something
> like this?

The CursorMoved autocommand event may do what you want.  See:

    :help CursorMoved

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190513181120.GA12153%40phoenix.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: triggering macro on navigation to new line

Ed Peschko
Gary,

thanks for this tip, yes it looks like I could use it to do what I
want but my concern is speed. I don't want to trigger a potentially
expensive macro each time the cursor moves anytime, just when the line
number changes.

So perhaps there is a need for CursorLineMoved? I see in vim where I
might be added, but I haven't contributed patches to vim before, so
i'm not sure on how to go about it.

Ed

On Mon, May 13, 2019 at 11:11 AM Gary Johnson <[hidden email]> wrote:

>
> On 2019-05-13, Ed Peschko wrote:
> > All,
> >
> > I just found :set nolazyredraw, which is *very* nice in speeding up
> > user interaction time, and which helps immensely with my goal of a
> > quickfix-like editing mode (see the post that I made earlier), so the
> > only thing left is if there is a way to trigger an action when you go
> > to a new line, whether you:
> >
> > 1. search for a pattern
> > 2. do :<lineno>
> > 3. hit j or k, up-arrow, down-arrow
> >
> > I suppose I could re-map each of these actions but IMO it would be a
> > lot cleaner if something universal existed. Does vim have something
> > like this?
>
> The CursorMoved autocommand event may do what you want.  See:
>
>     :help CursorMoved
>
> Regards,
> Gary
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190513181120.GA12153%40phoenix.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CACQ%2BYcv%3D3VbQ8vV3hqJ9F_S1XFpift%3Dh7QAiiXkjbT_GTa1O8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: triggering macro on navigation to new line

Gary Johnson-4
On 2019-05-13, Ed Peschko wrote:

> Gary,
>
> thanks for this tip, yes it looks like I could use it to do what I
> want but my concern is speed. I don't want to trigger a potentially
> expensive macro each time the cursor moves anytime, just when the line
> number changes.
>
> So perhaps there is a need for CursorLineMoved? I see in vim where I
> might be added, but I haven't contributed patches to vim before, so
> i'm not sure on how to go about it.

I don't think we need Yet Another Event for this special case.  The
usual approach to this sort of problem is to make an inexpensive
test early in the process so that you don't spend time considering
cases you don't care about.  In this case, you could cache the last
cursor line location and test against that early in the
autocommand command, perhaps something like this:

    :let g:prev_line = 0
    :au CursorMoved if line('.') != g:prev_line
        \ | let g:prev_line = line('.')
        \ | " other stuff
        \ | endif

Note that you could have just jumped to the same line number in
a different buffer, so you should test the buffer number, too,
perhaps with getcurpos() instead of line() to get both the buffer
number and the line number.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190513195231.GC12153%40phoenix.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: triggering macro on navigation to new line

Ed Peschko
Gary,

Yes I was thinking of that - a special check - but any perceptible
delay on the part of vim for what is such a common operation
(basically any operation) really goes against what I'm trying to get
at here usability wise. I really want this to be as close to a zero
cost operation as possible.

Plus there is always the cost of eval. I'm not sure if vim saves
internal vimscript compiles of a given macro for future evals of the
same macro. How much of a startup time would those checks impose? And
my ultimate language of choice would either be perl or python so
people could configure it without knowing vim regular expressions, and
i'm not sure if vim stores perl/python as bytecode either, or
(shudder) actually executes a subprocess.

In any case I'll play around with it and thanks for all the info.

On Mon, May 13, 2019 at 12:52 PM Gary Johnson <[hidden email]> wrote:

>
> On 2019-05-13, Ed Peschko wrote:
> > Gary,
> >
> > thanks for this tip, yes it looks like I could use it to do what I
> > want but my concern is speed. I don't want to trigger a potentially
> > expensive macro each time the cursor moves anytime, just when the line
> > number changes.
> >
> > So perhaps there is a need for CursorLineMoved? I see in vim where I
> > might be added, but I haven't contributed patches to vim before, so
> > i'm not sure on how to go about it.
>
> I don't think we need Yet Another Event for this special case.  The
> usual approach to this sort of problem is to make an inexpensive
> test early in the process so that you don't spend time considering
> cases you don't care about.  In this case, you could cache the last
> cursor line location and test against that early in the
> autocommand command, perhaps something like this:
>
>     :let g:prev_line = 0
>     :au CursorMoved if line('.') != g:prev_line
>         \ | let g:prev_line = line('.')
>         \ | " other stuff
>         \ | endif
>
> Note that you could have just jumped to the same line number in
> a different buffer, so you should test the buffer number, too,
> perhaps with getcurpos() instead of line() to get both the buffer
> number and the line number.
>
> Regards,
> Gary
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20190513195231.GC12153%40phoenix.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CACQ%2BYcvxn-dGgRG%3DUQJp_W92hs4peWBzujp0fb3GHXMKFbCvPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.