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

Behaviour of one-character operator maps #82

Closed
majutsushi opened this issue Feb 19, 2014 · 6 comments
Closed

Behaviour of one-character operator maps #82

majutsushi opened this issue Feb 19, 2014 · 6 comments

Comments

@majutsushi
Copy link

I use the operator maps suggested in the manual, like omap f <Plug>Sneak_f. But if try to use them with for example dfe or vfe it always executes the action to the first match and then highlights the rest. I guess this is consistent with the way normal jumping works, but it makes it essentially impossible to for example delete to a specific match in a line. Maybe it would make sense for operator-pending maps (and possibly visual-mode maps too) to ask where to jump to before executing the action.

@justinmk
Copy link
Owner

So you have let g:sneak#streak=1 and you want the 1-character maps to show targets--right?

The <Plug>Sneak_f/t convenience maps, by default, do not invoke streak-mode because I'm guessing most people don't want that for f or t. But those are just the convenience maps. You can instead create your own omap like this:

onoremap <silent> f   :call sneak#wrap(v:operator, 1, 0, 1)<cr>
onoremap <silent> F   :call sneak#wrap(v:operator, 1, 1, 1)<cr>

Notice the last argument is 1. This will cause dfe to invoke streak-mode if there are >2 matches. If you want to always invoke streak-mode, change that argument to 2.

Note: an upcoming commit will add an extra parameter to sneak#wrap(), so I apologize in advance, because the above sample will break after that commit. But after that commit I will maintain backwards compatibility.

But if try to use them with for example dfe or vfe it always executes the action to the first match

Don't forget that [count] works too. 2dfe or d2fe will delete up to the 2nd match.

@majutsushi
Copy link
Author

Right, I forgot to mention that I was using streak mode. You mappings seem to work, thanks! By the way, I noticed that in the help file the sneak#wrap() function has a reference (meaning it's surrounded by ||, but not an actual entry that it refers to.

The only thing that would be nice now if you could restrict these mapping to the current line (as standard f/t do) so that if there is only one match on the current line it gets jumped to immediately.

@justinmk
Copy link
Owner

Thanks for the heads up about the doc. #84

if there is only one match on the current line it gets jumped to immediately.

Hadn't thought about that angle. Streak-mode always jumps to the first match, so I assume you mean don't show target labels.

I like your idea because it is nearly deterministic if the user is targeting something on the current line, to guarantee no nagging target labels. If the user is targeting some other line, especially with 1 character, then target-label mode should reasonably be expected, so that's also deterministic (for 1-char at least).

I think somewhere in there is a really good compromise, better than the current default >2 matches thing. Made an issue: #85

Thanks!

@haya14busa
Copy link
Contributor

@majutsushi

FYI, If you use vim-sneak as a streak mode vim-easymotion already implementd within line motion which working range is only current line.

(If you use vim-sneak as a vanilla sneak, just ignore me.)

You can map it like this.

omap f <Plug>(easymotion-fl)
xmap f <Plug>(easymotion-fl)
omap t <Plug>(easymotion-tl)
xmap t <Plug>(easymotion-tl)

omap F <Plug>(easymotion-Fl)
xmap F <Plug>(easymotion-Fl)
omap T <Plug>(easymotion-Tl)
xmap T <Plug>(easymotion-Tl)

If there is only one match on current line, jump to target immediately like default vim behavior without activating EasyMotion prompt.

So I think you like it this motions.

Also note EasyMotion implement 2-key find motion like vim-seek/vim-sneak, so you can use it as default streak mode.

" Disable default mappings
let g:EasyMotion_do_mapping = 0

" This is bi-directional(forward/backward) motion.
nmap s <Plug>(easymotion-s2)

" nmap s <Plug>(easymotion-f2)
" nmap S <Plug>(easymotion-F2)

@justinmk
Copy link
Owner

Leaving this open to track enhancement:

make operator-pending maps (and possibly visual-mode maps too) to ask where to jump to before executing the action.

@justinmk
Copy link
Owner

Closing in favor of #88 and #123

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

No branches or pull requests

3 participants