Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can vim-repeat be used to make insert and append operators repeatable? #75

Closed
blasco opened this issue Oct 21, 2019 · 4 comments
Closed

Comments

@blasco
Copy link

blasco commented Oct 21, 2019

I'm trying to make the following operators repeatable:

https://github.com/mwgkgk/vim-operator-insert

I tried adding:

function! s:operator_insert_i(motion_wise)
  call cursor(getpos("'[")[1:])
  startinsert
  silent! call repeat#set("\<Plug>(operator-insert-i)", -1)
endfunction

But when I do giiw (go insert in word) and insert something, when I repeat it doesn't repeat the whole giiw, it just inserts at the current cursor position:

this is an exa<cursor>mple

giiw and type new_

this is an new_<cursor>example

ge then .

this is anew_n new_<cursor>example

instead of

this is new_an new_<cursor>example

Any idea on how to approach this? I think an insert and append operator would be quite useful (specially combined with vim-targets)

@tpope
Copy link
Owner

tpope commented Oct 22, 2019

I think what is happening is the undo operation is created after leaving insert mode, which means the call to repeat#set() is superseded. You could maaaaaaybe leverage InsertLeave to pull this off, or some other clever trick, but I think you're on your own to figure that out.

@tpope tpope closed this as completed Oct 22, 2019
@blasco
Copy link
Author

blasco commented Oct 22, 2019

Ok, thanks for the guidance.

@blasco
Copy link
Author

blasco commented Oct 22, 2019

If possible, could you clarify me a little bit how it works? Because there is only one call repeat#set(), which from what I've seen needs to be placed just after the operation is finished? But how does it know when it started? How does it know to what text object it applies?

@tpope
Copy link
Owner

tpope commented Oct 22, 2019

I don't know that it can be done, but I would start by setting a private variable to b:changedtick in your function (and another variable for the text object etc) and then check that it's 1 higher in InsertLeave.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants