How to find out if InsertLeave was the result of a change

There are basically two types of commands in Vim that can make it go into insert mode:

Commands that simply add something, for example: i , i , a , a (other than using backspace). Or delete a piece of text, for example: c[motion] , C , s , v[motions]s .

I would like to bind the InsertLeave event, but in my code I need to know what type of change it is (insert like i , or change like cw ). Is there any way to find this?

+4
source share
2 answers

Will the i<BS><BS><BS>bar read the insert or change? If the latter, you can :undo change to InsertLeave , save the lines affected by it (ie '[,'] ) :redo , and then compare both sets. If there is “just more text”, this is an insert, otherwise it is a change.

+1
source

There is one difference you can use: change commands all change case (unless the black hole case was explicitly specified by adding "_ ), while there are no inserts (well, except ". ).

If you take a “snapshot” of the default register earlier (for example, using the CursorMoved,CursorHold ) and compare the contents on InsertLeave , you can find out.

0
source

All Articles