In Vim 8.x, is there a way to specify a same-line action when using g@ and :set opfunc to define a custom command? In other words, I know how to use map to:
noremap <silent> <a-z> :set opfunc=MyFuncOp<cr>g@
Let's say MyFuncOp does some custom type of yank or delete. It works perfectly to press alt-z then j and do that on two lines. But what if you need it on just one line... just like you would with repeated operators like dd or yy? Mapping g@g@ doesn't work. How do you convey a single linewise (i.e., the current line) to a g@ custom command?
EDIT:
I later learned that motion _ (with no count) seems to make commands work essentially on the same-line. So d_ is like dd and y_ is like yy, so my custom opfunc's g@ followed by _ also does what I want. I ultimately followed Matt's #(2) answer below and operator-mapped <Enter> to _ as follows (so as not to have to press shift every time):
onoremap <enter> _
Vim help says:
_ [count] - 1 lines downward, on the first non-blank character |linewise|.
This seemed not as clear to me that it would do what I needed, but because it's linewise (as romainl points out), it in fact, does the job!
No, it's not to be implemented by custom g@
only. Basically, you have two options.
Either, (1) create also a custom motion (mapmode-o) that includes the whole current line. So, say, you have Y
to perform custom "yank" and al
to select current line in operator pending mode. Then typing Yal
will do. There are many existing implementations of such "custom motion" out there. And it's also pretty easy to devise another one yourself.
Or (2), define special version of your mapping. That is, both Y
to invoke g-at, and YY
to perform custom operation on the current line without entering the operator pending mode. Proper use of functions and commands should help to avoid code duplication in this case.