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

Convention for remapping layer's key bindings? #3018

Closed
arnm opened this issue Sep 13, 2015 · 17 comments
Closed

Convention for remapping layer's key bindings? #3018

arnm opened this issue Sep 13, 2015 · 17 comments
Labels
Key Bindings Question stale marked as a stale issue/pr (usually by a bot)

Comments

@arnm
Copy link

arnm commented Sep 13, 2015

I prefer jkl; to hjkl and would like to apply this as much as possible across all layers. It is easy enough to remap the evil motion keys in dotspacemacs/config but I don't know if it's that simple for bindings specified in other layers.

I specifically want to override the gh gj gk gl in the org layer right now but I do see myself needing to remap other bindings specified in other layers.

So my questions are:

  1. How can I go about remapping those org layer commands?
  2. Is there a common way to remap keybindings specified in layers?

P.S I'm new to spacemacs...I see there are a lot of conventions and was wondering if there was one for remapping bindings specified in layers.

@arnm
Copy link
Author

arnm commented Sep 14, 2015

I was able to remap the org-mode bindings but I had to look though evil-org code instead of just the org layer. I guess question 2 depends on the layer itself...

(evil-define-key 'normal evil-org-mode-map
    "gj" 'outline-up-heading
    "gk" 'org-forward-heading-same-level
    "gl" 'org-backward-heading-same-level
    "g;" 'outline-next-visible-heading)

@syl20bnr
Copy link
Owner

Look at key translation, for instance:

(define-key key-translation-map (kbd ";") (kbd "l"))

@arnm
Copy link
Author

arnm commented Sep 14, 2015

Haven't looked too into to much yet but as of now the key translation works but it also takes effect in insert mode which is not desired.

Is there an equivalent to vim's noremap for example in emacs?

@syl20bnr
Copy link
Owner

Try:

(evil-define-key 'normal key-translation-map (kbd ";") (kbd "l"))

This should work only in normal state, rince and repeat for other states :-)

@arnm
Copy link
Author

arnm commented Sep 16, 2015

hmm I see what you are trying to do but it doesn't seem to work for me :(

  ;; remappings
  (evil-define-key 'normal key-translation-map (kbd "j") (kbd "h"))
  (evil-define-key 'normal key-translation-map (kbd "k") (kbd "j"))
  (evil-define-key 'normal key-translation-map (kbd "l") (kbd "k"))
  (evil-define-key 'normal key-translation-map (kbd ";") (kbd "l"))

@mmlac-bv
Copy link

mmlac-bv commented Oct 8, 2015

I tried this and I get the following error:

Wrong type argument: symbolp, (evil-define-key (quote normal) key-translation-map (kbd r) (kbd h))

when adding this to the end of (defun dotspacemacs/init ()

(evil-define-key 'normal key-translation-map (kbd "r") (kbd "h"))

Any ideas why this is happening?
emacs 24.5.1 on mac, latest spacemacs

If I add it to the (defun dotspacemacs/config ()

(evil-define-key 'normal key-translation-map (kbd "σ") (kbd "h"))

it just says σ is undefined

@nugend
Copy link

nugend commented Dec 14, 2015

I'm trying to add the following binding:

(evil-define-key 'normal evil-org-mode-map
  "C-o" 'org-insert-heading-after-current
  "C-O" 'org-insert-heading
  )

Doesn't seem to work. Also tried using (with-eval-after-load 'org-mode ...) to make sure it ran after any other bindings were defined. That didn't work either.

@jason
Copy link

jason commented Feb 18, 2016

This works under user-configuration. If you're wondering, these are keybindings for the Workman keyboard.

(define-key evil-normal-state-map "h" 'evil-yank)
(define-key evil-normal-state-map "n" 'evil-next-line)
(define-key evil-normal-state-map "e" 'evil-previous-line)
(define-key evil-normal-state-map "o" 'forward-char)

(define-key evil-normal-state-map "k" 'evil-forward-WORD-end)
(define-key evil-normal-state-map "l" 'evil-open-below)
(define-key evil-normal-state-map "L" 'evil-open-above)
(define-key evil-normal-state-map "j" 'evil-search-forward)
(define-key evil-normal-state-map "H" 'evil-yank-line)

@ghost
Copy link

ghost commented Jul 1, 2016

Before using Spacemacs (i.e. just using Evil), I used the following with some success:

;; Modify evil-mode keybindings from hjkl motion to jkl;
(define-key evil-normal-state-map "H" 'evil-join)
(define-key evil-motion-state-map "j" 'evil-backward-char)
(define-key evil-motion-state-map "J" 'evil-window-top)
(define-key evil-motion-state-map "k" 'evil-next-line)
(define-key evil-motion-state-map "l" 'evil-previous-line)
(define-key evil-motion-state-map ";" 'evil-forward-char)
;; (define-key evil-motion-state-map ":" 'evil-window-bottom)
(define-key evil-motion-state-map "h" 'evil-repeat-find-char)
(define-key evil-window-map "j" 'evil-window-left)
(define-key evil-window-map "J" 'evil-window-move-far-left)
(define-key evil-window-map "k" 'evil-window-down)
(define-key evil-window-map "K" 'evil-window-move-very-bottom)
(define-key evil-window-map "l" 'evil-window-up)
(define-key evil-window-map "L" 'evil-window-move-very-top)
(define-key evil-window-map ";" 'evil-window-right)
;; (define-key evil-window-map ":" 'evil-window-move-far-right)

Seems to work alright in Spacemacs, and probably goes some way towards satisfying the OP's desires.

Ideally, I think that the option to use jkl; instead of hjkl would be provided via some kind of Spacemacs layer, or Emacs mode, rather than simply by pasting the code above into the .spacemacs file, but I don't yet grok Spacemacs well enough to know which of those two approaches would be most appropriate, nor how to build a suitable layer or mode. I would be very grateful to anyone else who does, though!

@syl20bnr
Copy link
Owner

syl20bnr commented Jul 1, 2016

We could leverage the new keyboard-layout layer in develop branch.

@ghost
Copy link

ghost commented Aug 10, 2016

Bountysource

@YayC
Copy link

YayC commented Aug 26, 2016

To make some evil-org keybinding overrides, I had to use with-eval-after-load and plain define-key (not evil-define-key):

(with-eval-after-load 'evil-org
    (define-key evil-org-mode-map (kbd "<insert-state> M-t") #'my-insert-sub-todo)
    (define-key evil-org-mode-map (kbd "<normal-state> M-t") #'my-insert-sub-todo))

Strangely, remapping T works without any of that:

(evil-define-key 'normal evil-org-mode-map "T" #'my-insert-todo)

Which I don't understand, even after a quick look at https://github.com/syl20bnr/spacemacs/blob/a298a5a311dfe8b449b5f538740303f1ab3d5695/layers/org/extensions/evil-org/evil-org.el

Both are in the body of dotspacemacs/user-config in my .spacemacs file

@LeMikaelF
Copy link

LeMikaelF commented Jul 31, 2019

@arnm This is an old post, but I spent hours trying to get this to work. The solution is:

(evil-define-key 'normal global-map (kbd "j") (kbd "h"))

(cross-posted from my answer on Stackoverflow)

@duianto
Copy link
Collaborator

duianto commented Jul 31, 2019

@LeMikaelF Thanks for posting a solution.

A note about github comments, you can edit one of your comments or even delete it (for example the duplicate without the stackoverflow link), by clicking on the three dots ... in the top right corner of your comment. That opens a menu where you can choose an action.

@LeMikaelF
Copy link

@duianto Oops! Thanks for pointing that out, my mistake.

@mfierro0
Copy link

mfierro0 commented Dec 7, 2019

@LeMikaelF Thanks for posting! Probably saved me a few hours too :)

@github-actions
Copy link

github-actions bot commented Dec 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Dec 6, 2020
@github-actions github-actions bot closed this as completed Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Key Bindings Question stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

9 participants