sponsor Vim development Vim logo Vim Book Ad

hookcursormoved : Facilitate definition of triggers on CursorMoved[I] events

 script karma  Rating 8/2, Downloaded by 4052  Comments, bugs, improvements  Vim wiki

created by
Tom Link
 
script type
utility
 
description
This experimental plugin provides some help with the definition of
functions that should be called when the cursor position changed.

When the cursor position changes, it first checks if a certain condition
is met and then calls functions registered in
[bg]:hookcursormoved_{CONDITION} (an array).

Pre-defined conditions:
    linechange
        The line-number has changed.
    parenthesis
        Cursor is over (), [], or {}.
    syntaxchange
        The syntax group under the cursor has changed (i.e. the cursor
        has moved in/out of a syntax group.
    syntaxleave
        b:hookcursormoved_syntax (ARRAY) should contain the syntax names
        which should run the hook code.
    syntaxleave_oneline
        Same as a above but check also for changes of the line number.

In order to define a new conditions, you have to define a function
"HookCursorMoved_{CONDITION}(mode)", which returns true if the condition
is met.

Functions are best registered using |hookcursormoved#Register()|.
Example: >

    function! WhatsGoingOn(mode) "{{{3
        if mode == 'i'
            DoThis
        elseif mode == 'n'
            DoThat
        endif
    endf

    call hookcursormoved#Register('b', 'syntaxchange', function('WhatsGoingOn'))

 
install details
Edit the vba file and type: >

    :so %

See :help vimball for details. If you have difficulties or use vim 7.0,
please make sure, you have the current version of vimball
(vimscript #1502) installed.


Also available via git
http://github.com/tomtom/hookcursormoved_vim
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
hookcursormoved.vba.gz 0.9 2009-10-18 7.0 Tom Link - hookcursormoved#Register: Print a message on unknown hooks (don't throw an error)
- hookcursormoved#Register: If g:hookcursormoved_linechange is undefined, assume the plugin wasn't loaded.
hookcursormoved.vba.gz 0.8 2008-07-11 7.0 Tom Link hookcursormoved#Register: Allow deregister
hookcursormoved.vba.gz 0.7 2007-11-21 7.0 Tom Link - Minor tweaks
- FIX: Check correct column in s:CheckChars()
hookcursormoved.vba.gz 0.6 2007-11-18 7.0 Tom Link - Check correct column in syntax* tests.
hookcursormoved.vba.gz 0.5 2007-11-12 7.0 Tom Link - hookcursormoved#Register() takes mode as optional 3rd argument which
allows to check a condition only in insert or only in normal mode.
- Defined parenthesis_round_open and parenthesis_round_close.
- Modes are now defined via the g:hookcursormoved_{mode} variable (the
function name as string).
hookcursormoved.vba.gz 0.4 2007-10-29 7.0 Tom Link - Defined parenthesis_round
- FIX: parenthesis
hookcursormoved.vba.gz 0.3 2007-10-12 7.0 Tom Link - Defined parenthesis, syntaxleave_oneline conditions
- Removed namespace parameter (everything is buffer-local)
- Perform less checks (this should be no problem, if you use #Register).
hookcursormoved.vba.gz 0.2 2007-10-04 7.0 Tom Link - Renamed s:Enable() to hookcursormoved#Enable()
- Renamed s:enabled to b:hookcursormoved_enabled
ip used for rating: 3.236.219.157

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github