sammito-1 · 2022-11-21 03:48
Hey guys! So sorry if this is a stupid question — I am a former user of VSCode with vim key bindings and am trying to replicate my workflow in Spacemacs in particular.
I am looking to see if I can replicate VSCode-Vim Easymotion *bidirectional* word highlighting. I can replicate forward and backward word highlighting for jumps, just not bidirectional.
For anyone who has hacked together a solution, any suggestions?
I would like to press space bar and maybe one character and be able to jump to any word shown on the screen.
andyjda · 2022-11-21 04:16
>I would like to press space bar and maybe one character and be able to jump to any word shown on the screen.
It sounds like [avy](https://github.com/abo-abo/avy) is what you're looking for?
sammito-1 · 2022-11-21 04:18
avy-goto-word-0 is PERFECT. Thank you!!!
I’m such a noob when it comes to eMacs layers. Sorry for not finding this myself.
andyjda · 2022-11-21 04:50
No problem!
That’s what forums like this are for (:
There’s tons of packages and functionalities that are pretty hard to describe and impossible to find through search engines/the built-in help system, even though they’re quite useful. Don’t hesitate to ask when needed
sammito-1 · 2022-11-21 05:01
I’m still a bit confused on how to remap a key combination to an Avy command.
For example, I’d like to remap “SPC j j” (which is normally avy timer in Spacemacs) to “avy-goto-word-0” and I have absolutely no clue what to search to figure this out.
Regardless, thanks again!
[deleted] · 2022-11-21 15:11
[deleted]
andyjda · 2022-11-21 16:16
The best documentation on key bindings is probably in the [Mastering Emacs book](https://www.masteringemacs.org/article/mastering-key-bindings-emacs).
Your config is a bit different from mine so I can't give you a full answer but I'll try to point you in the right direction.
Normally, something like:
(global-set-key (kbd "SPC j j") #'avy-goto-word-0)
would work. This essentially maps the given key-sequence to the given function, inside the global keymap (see the link above for an explanation on keymaps).
One possible issue: it looks like Spacemacs uses [evil-mode](https://github.com/emacs-evil/evil), which is what allows it to recognize SPC as a prefix key. I don't use evil-mode, so when I run the above snippet I get an error (`*** Eval error *** Key sequence SPC j j starts with non-prefix key SPC`).
If you get the same problem, maybe you could look into the documentation [here](https://www.gnu.org/software/emacs/manual/html_node/elisp/Changing-Key-Bindings.html), and use `subsititute-key-definition`:
(substitute-key-definition
'avy-timer 'avy-goto-word-0
(current-global-map))
(TL;DR the above is probably what you should try first)
This is assuming that `avy-timer` is bound to this key combination inside of the `global-map`. We can't be sure of that (it might be in another, mode-specific map). So the first thing I'd advise you to do after this (whether it works or not), is to take a look at how Spacemacs uses keybindings. A quick [grep](https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/) for "avy-timer" inside the Spacemacs source-directory should show you where this is set.