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

f,F,t,T do not work in macros #7

Closed
alexander-born opened this issue Jun 16, 2021 · 11 comments
Closed

f,F,t,T do not work in macros #7

alexander-born opened this issue Jun 16, 2021 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@alexander-born
Copy link

Love the plugin, but f,F,t,T do not work in macros anymore.

@ggandor
Copy link
Owner

ggandor commented Jun 16, 2021

Thanks for the report! Yeah, I can reproduce such issues. I'm clueless at the moment, but will investigate this.

@ggandor ggandor added bug Something isn't working help wanted Extra attention is needed labels Jun 16, 2021
@ggandor ggandor pinned this issue Jun 19, 2021
@sQVe
Copy link

sQVe commented Jun 21, 2021

This also applies to the normal command. I have to run :norm! for f@dW to work.

@sQVe
Copy link

sQVe commented Jun 21, 2021

vim-sneak also has this problem but only when setting let g:sneak#s_next = 1.

@ggandor
Copy link
Owner

ggandor commented Jun 21, 2021

This reinforces my suspicion that this is about the "instant-repeat" feature, maybe feedkeys() causes problems...? I have to check how clever-s/f is implemented in Sneak, it's been a while since I've studied that.

@ggandor
Copy link
Owner

ggandor commented Jun 21, 2021

This might be related: justinmk/vim-sneak#264

@sQVe
Copy link

sQVe commented Jun 21, 2021

@ggandor ☝🏼 issue is for sure related to that.

@rktjmp
Copy link
Contributor

rktjmp commented Jun 26, 2021

For others, my work around is this, which seems to work fine:

" divert lightspeed in macros because fFtT misbehave
nmap <expr> f reg_recording() .. reg_executing() == "" ? "<Plug>Lightspeed_f" : "f"
nmap <expr> F reg_recording() .. reg_executing() == "" ? "<Plug>Lightspeed_F" : "F"
nmap <expr> t reg_recording() .. reg_executing() == "" ? "<Plug>Lightspeed_t" : "t"
nmap <expr> T reg_recording() .. reg_executing() == "" ? "<Plug>Lightspeed_T" : "T"

For what it's worth, I've previously had issues with feedkeys in macros, my solution was replacing it with <expr> maps.

Not sure if that's appropriate/doable here, nor whether the issue was because of incompatibilities around mixing feed keys and macros or if I was just misapplying feed keys (likely).

@ggandor
Copy link
Owner

ggandor commented Jun 26, 2021

@rktjmp Perfect workaround, many thanks! I didn't know about the reg_recording and reg_executing functions. We should probably add this to the readme.

It's a pity that we cannot do something similar for norm (as norm! disables all the other custom mappings, so that is not ideal).

@ggandor
Copy link
Owner

ggandor commented Jun 26, 2021

Eureka, it seems we have caught the problem, and there is a solution for this, the workaround is not even necessary! From :h feedkeys():

By default the string is added to the end of the typeahead
buffer, thus if a mapping is still being executed the
characters come after them.  Use the 'i' flag to insert before
other characters, they will be executed next, before any
characters from a mapping.

With the i flag added to feedkeys, macros and norm work without issues! With reg_recording and reg_executing available, we can even limit the scope of f/t to the current line in those cases (that is probably the more intuitive behaviour - or we can make it optional, however we want).

@ggandor
Copy link
Owner

ggandor commented Jun 26, 2021

I have to think through how best to handle limiting the scope to the current line, we should probably open a new issue for that. (Edit: #14)

@alexander-born
Copy link
Author

Great find! Works as expected now.
I hope the i flag fixes a similar problem in nvim-compe. See hrsh7th/nvim-compe#416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants