hlissner / evil-snipe

2-char searching ala vim-sneak & vim-seek, for evil-mode
MIT License
340 stars 25 forks source link

no clean way to use different keys for snipe commands #46

Closed wbolster closed 4 years ago

wbolster commented 7 years ago

hi, first of all, evil-snipe is fantastic. thanks.

that said, i am having some trouble making it work with different keys. i use the colemak keyboard layout, and use evil-colemak-basics to use different keys for various evil commands.

recently i decided to also move the functionality for f and t to different keys for improved ergonomics and preserved muscle memory. in short, i want t to jump forwards, and j to jump backwards. with colemak, keys are at a different location, and t and j fit in my hybrid qwerty/colemak keybinding scheme for non-insert states); details here.

this works fine for evil's built-in evil-find-char-* commands. however, i want to use evil-snipe to spice up f and t. at first i thought all that was needed would be binding evil-snipe-f and friends to the appropriate keys. i do not use evil-snipe-override-mode since that does not use the keys i want, but with a few key mappings the result will be the same.

it turns out this works fine for triggering evil-snipe, but repeating a snipe fails. the reason is that the transient keymap hardcodes the key bindings "f" (forward) and "t" (backward) in the evil-snipe-def macro.

i managed to get it working using this code:

(evil-snipe-def 1 inclusive "t" "T")
(evil-snipe-def 1 exclusive "j" "J")
(evil-define-key '(motion normal visual) keymap
  "t" 'evil-snipe-t
  "T" 'evil-snipe-T
  "j" 'evil-snipe-j
  "J" 'evil-snipe-J)

...but i am not very happy about it:

perhaps there is a better way to get this working? perhaps (this-command-keys) can be used instead of hardcoding the keys?

hopefully i made the issue clear. ideas and discussion more than welcome. :tulip:

hlissner commented 7 years ago

Hey there! You're right, this isn't ideal and I've certainly neglected non-QWERTY layouts. I'll look into this (and this-command-keys) this week and see if I can cook something up that's flexible yet backward compatible.

hlissner commented 6 years ago

It's been almost a year. I've looked into this a number of times and couldn't come up with anything clever, so I think I'll go with the simple solution: a evil-snipe-style switch variable that defaults to 'qwerty and accepts 'colemak (or set to nil and left to the user to define their own -- evil-snipe-def is no longer a private macro).

That said, I'd like to include a reasonable default for colemak users, but I'm not familiar with the layout, so I'm hoping you can offer some advice: are t, T, j and J good colemak alternatives, or are they simply your personal preference? Could you also offer alternatives for s and S as well?

wbolster commented 6 years ago

vim layouts on colemak are plenty, my own evil-colemak-basics obviously the best among them :wink:.

using evil-snipe-def is the most flexible way i would say. this is what evil-colemak-basics already does:

        (evil-snipe-def 1 inclusive "t" "T")
        (evil-snipe-def 1 exclusive "j" "J")

(https://github.com/wbolster/evil-colemak-basics/blob/master/evil-colemak-basics.el#L111-L114)

no opinion on s and S since i have those disabled (i use avy / evil-easy-motion).

wbolster commented 6 years ago

using evil-snipe-def overwrites the old commands/functions though, perhaps the macro could take an argument so that it can create unique names, but i do not have a strong opinion on that since i only use colemak and never switch between layouts (my brain would melt if i were to try).

joefromct commented 4 years ago

Hi, dvorak user here. I've been getting into evil-snipe more and the ; is tuff to hit for me many times a day.

I'll post back if i come up with something better for myself.

wbolster commented 4 years ago

@joefromct have you tried my evil-snipe-def approach? it works fine actually. see above or consult my dotfiles

joefromct commented 4 years ago

I actually realized i had a different ailment regarding my evil-snipe-needs as i dug into it... i think this does the trick for me but curious if this would be the correct way.. i haven't tinkered with emacs lisp too much.

My root issue was ; isn't dvorak-accessible for forward-key that i believe is hard-coded for the macro generation?

With the above commit and something like this:

(map! :nv "<SPC>"   'evil-snipe-f 
      :nv "S-<SPC>" 'evil-snipe-s)

my sore hands seem to be much happier for the past 1hr...

Also, I now realize that my issue was different than yours? Let me know if that's the case and I'll make myself a new issue, and apologies for hi-jacking the thread.