emacs-evil / evil-magit

Black magic or evil keys for magit
https://github.com/justbur/evil-magit
GNU General Public License v3.0
273 stars 16 forks source link

Map 'evil-yank' to 'y'? #11

Closed cmlaverdiere closed 8 years ago

cmlaverdiere commented 8 years ago

It would be convenient to be able to yank selections from the magit buffers, like diffs and logs. Would this be possible?

justbur commented 8 years ago

It's possible somehow I'm sure but there is a conflict with y so I'd probably want it to be optional. Are you familiar with C-w I think it is? Is that what you are trying to do?

cmlaverdiere commented 8 years ago

I wasn't familiar with C-w but that looks like the correct behavior. Having y optionally map to magit-copy-section-value would be great.

justbur commented 8 years ago

Easy enough. What would you like to do with magit-show-refs-popup (currently bound to y)?

On Thu, Dec 10, 2015 at 1:52 PM Chris Laverdiere notifications@github.com wrote:

I wasn't familiar with C-w but that looks like the correct behavior. Having y optionally map to magit-copy-section-value would be great.

— Reply to this email directly or view it on GitHub https://github.com/justbur/evil-magit/issues/11#issuecomment-163715943.

cmlaverdiere commented 8 years ago

I don't use show-refs often, so your call.

justbur commented 8 years ago

4a8b52a

Set evil-magit-use-y-for-yank to t and you will get

yy => magit-copy-section-value
yb => magit-copy-buffer-revision
yr => magit-show-refs

Let me know what you think. I'm happy to make changes

syl20bnr commented 8 years ago

Another solution would be to make y work only in visual mode so magit-show-refs-popup is still available when nothing is selected.

syl20bnr commented 8 years ago

Forget my proposition, I didn't see that it was available under yr. The OP asked for yanking selection though.

justbur commented 8 years ago

@syl20bnr technically there's no visual mode in evil-magit anyway

syl20bnr commented 8 years ago

@justbur Do you think this is possible to have a visual state ? If this is consistent with raw magit in emacs state then I guess it is OK. TBH I find this a bit disappointing, I often use visual state in evilified magit especially while writing commit message, I go to the diff on the side to copy some stuff.

justbur commented 8 years ago

@syl20bnr I keep everything in motion state just to avoid headaches with switching states. You can select with "v", but in evil-magit this uses set-mark-command instead of changing states. If you want the ability to copy text linewise, I can do that without visual state, and linewise operations are what default magit supports (C-f is not forward-char for example). If you want the ability to copy arbitrary chunks of text, that's a little more involved.

I just didn't think about copying text in magit buffers (I'd just pop open the file if I was going to do that), but it sounds like people do so I'll add the option.

syl20bnr commented 8 years ago

@justbur I disagree with this design choice, this is evil-magit not hybrid-magit, OTOH magit design prevents forward char so... :-) Maybe the best is to wait and see if other users request a visual state when they have yy and yb.

justbur commented 8 years ago

@syl20bnr in magit you have operations that you perform after selecting text if you enter visual state you have to make sure those operations are still available (not shadowed by visual state commands). What does evilification do about this? Doesn't it only affect evilified-state?

syl20bnr commented 8 years ago

This is solved in evilified state by emptying the whole keymap of visual state and rebind only y to evil-yank and ESC. Corresponding code is here: https://github.com/syl20bnr/spacemacs/blob/develop/layers/+distribution/spacemacs-base/local/evil-evilified-state/evil-evilified-state.el#L85-L87

syl20bnr commented 8 years ago

@justbur but this is a bit trickier actually, the keys passing through the visual state keymap are intercepted by a pre-command-hook to redirect the key to evilified state map. I have a feeling that with your expertise and smart heriarchy of keymaps I could remove this hook.

justbur commented 8 years ago

Interesting. Magit changes the behavior of M-w if the region is active https://github.com/magit/magit/issues/1958

justbur commented 8 years ago

Actually... That means that vjjyy will select and copy text as I currently have it without further changes. It's not exactly vim because there are two "y"s, but it's pretty close. I could make that 1 "y" if people really wanted that...

@CLaverdiere Sorry for all of the spam. Let me know what you think about the current behavior and we can look into changes.

cmlaverdiere commented 8 years ago

The yy behavior is good, though just y to yank from a selection would be nicer, as it's closer to the usual evil behavior. I do like @syl20bnr's suggestion that this mapping would only apply in visual mode, as not to shadow the show-refs binding. If getting visual mode to work with evil-magit is too cumbersome though, I'm happy with what you've implemented.

As for the current set-mark-command behavior, I notice that when using C-w to copy (I assume the new yy works the same way), the last line in the selection isn't copied. Is this meant to happen or is it just on my end?

justbur commented 8 years ago

Just to be clear, I consider this feature experimental at this point, but I've introduced visual state (linewise only still v does exactly what you'd expect V to do in vim), and the new bindings are

yy => yank line
yr => magit-show-refs-popup
ys => magit-copy-section-value
yb => magit-copy-buffer-revision

In visual state
s => stage
u => unstage
...
y => evil-yank
cmlaverdiere commented 8 years ago

This is fantastic! Works exactly as expected. Thank you!

Unrelated, but I noticed while testing that '/' is mapped to evil-search-forward, but '?' isn't mapped to evil-search-backward. This would be a good remap since 'h' already opens the help menu.

justbur commented 8 years ago

I went back and forth on ? but I think you're right. I'll change it when I get a chance

justbur commented 8 years ago

@CLaverdiere I changed ? to search backward and then I changed my mind again and put it back to the help popup. My reasoning is that h is not obvious enough for help to vim users. To compensate I added instructions to the readme to show how to add ? for search backward.

cmlaverdiere commented 8 years ago

Agreed, thanks for the option.