3

I read on an old none commentable reddit that Tpope no longer uses his vim-repeat plugin, and instead uses g@. I have used g@ in plugins, and unstand you set opfunc first, then g@{motion} will run opfunc on the motion.

I have had some success using g@ when editing to repeat a titlecase function, but havent figured out how to repeat for example vim-surround functionality with it. Does anyone find it useful when editing text (i.e. outside the context of vim scripting).

8
  • I can't really answer your question, however I think you used @g instead of g@ in the title and the first sentence of your question and if I understand properly that is a typo (which would be worth editing to avoid confusion). Could you also link the Reddit post you are referring to just for my curiosity please?
    – statox
    Jul 6 '20 at 18:35
  • Also FWIW vim surround still seems to be using vim-repeat and his dotfiles still references the surround plugin code.
    – statox
    Jul 6 '20 at 18:47
  • @statox Fixed it thank you. I google the post but can't find it. It was a few months ago, but made a note to return to research. Jul 6 '20 at 19:10
  • 1
    If this is his plugins that hes using I don't see vim-repeat there. Leaving support in vim-surround for vim-repeat is different to not using vim-repeat. Jul 6 '20 at 20:43
  • 1
    1. He still uses vim-repeat for old scripts. 2. He tries to avoid the plugin for future scripts in favor of opfuncs (and he may refactor some old code to get rid of it). 3. He's right; the plugin has bugs, which native repetition can fix.
    – user938271
    Jul 7 '20 at 8:42
4

g@ is extremely useful for plugins and custom maps, but it's not so useful by itself.

One reason is that opfunc, which is a global option, needs to be set correctly before you type g@. Theoretically, you could use :set opfunc=MyFunc followed by g@ but you may as well create a mapping wrapper which does :set opfunc=myFunc<cr>g@ since then it works regardless of what opfunc was set to before.


Generally, a plugin which adds operators should use g@ so that repeating with . works. Likewise, a plugin which adds "whole operations" should support repeating by using g@l or similar.

Since plugins should be designed to allow repeating via ., there is no need to use g@. It is unlikely that you can repeat a plugin's map via g@ unless it was designed specifically to allow that. But in that case, the plugin would likely be designed to support . repeating.

2
  • "Since plugins should be designed to allow repeating via ." ... although I have found this is mostly not the case, I guess that is why vim-repeat exists in the first case? I think if you can repeat it with g@, then one might as well just use . instead, which means g@ is not very beneficial for editing use as you state. Jul 7 '20 at 10:06
  • Well, vim-repeat exists from a time long ago. I don't know of a case where g@ won't work but vim-repeat will (but might be wrong). The one advantage it still has is the interface is a bit nicer for plugins to use.
    – Mass
    Jul 8 '20 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.