5

How can I permanently rebind keys?

I'd like to rebind C-i, C-j, C-k, and C-l to act like the arrow keys. However, when using

(global-set-key (kbd "C-l") 'forward-char)

it will only do so for the session; the bindings don't persist after restarting Emacs.

Is there some way to automatically do this every time on startup or via a config file or something?

5
  • 4
    Welcome to Emacs.SE. As a general rule, please do a little background research before posting a question -- googling emacs config file will return the manual page for the init file as the first hit.
    – Dan
    Commented Oct 26, 2014 at 12:45
  • 3
    Well, I upvoted both the question and @Dan's comment. (I'm not completely sure why, but it felt right. ;-)). Such a newbie question should be OK for this site, I think. But such a comment is also helpful, to try to steer people to ask Emacs first. IOW, the question is a natural one, and we cannot fault newbies for not yet knowing how to ask Emacs itself for the answer.
    – Drew
    Commented Oct 26, 2014 at 17:02
  • @Drew That was the exact reasoning why I added the answer. We want this site to be useful to all emacs users: newbie to advanced. No one should go back unanswered as long as the question is emacs related :) Commented Oct 26, 2014 at 17:27
  • 1
    @kaushalmodi: And I'm glad to see that someone else (you, most likely) upvoted the question, which had several downvotes initially). It's not a great question, but it is certainly a reasonable question for a newbie to have.
    – Drew
    Commented Oct 26, 2014 at 17:38
  • Thank you to everyone who posted or upvoted for the pretty kind welcome to the community, despite the newbie question. I'm indeed a first-time emacs user (who knew), and had the great urge to change the keybindings at ~30% into the help-with-tutorial. While Dan's post (as well as other posts here) clearly solves the problem, I was for some reason stuck with always googling sth around key bindings, and although learning lots of other things in the process, I couldn't find a working answer. I hope this helps anyone who might get stuck in his googling/thought process in the same way as me.
    – Alex
    Commented Oct 28, 2014 at 21:56

2 Answers 2

7

As @Dan mentioned in his comment to your question above, you can do that by putting your customizations in a config file like ~/.emacs.d/init.el.

But I would recommend not overriding the C-i C-j C-k C-l keys as they serve some core functions like joining lines, killing text, etc.

Try out evil-mode instead if you need vim-style navigation.

I got used to C-b C-n C-p C-f keys by installing hardcore-mode.

2
  • +1 re: suggestion to rely only on C-b, C-n, C-p and C-f to move cursor. Before I got used to these shortcuts, I didn't quite appreciate just how much faster you can manipulate text/code/etc when your hands don't have to leave the "default position". (Though one of the temporary side effects is that you'll occasionally open a slew of new windows in your web-browser)
    – iceman
    Commented Oct 26, 2014 at 16:00
  • That's an interesting use of "default" finger position. Usually people mean the "home" row, i.e., "JKL;". Commented Oct 27, 2014 at 18:38
2

I use a similar cursor movement layout to what you want (IJKL, making for an inverse T), and absolutely love it. I got the initial idea from Xah Lee's ErgoEmacs keybinding project, now moved to Github: https://ergoemacs.github.io/

The only drawback is that when I first start using a new mode, I may have to clean up its keymap to follow my pattern, but this is fairly rare and a one-time-only operation.

2
  • You may find stackoverflow.com/questions/683425/… useful for never needing to modify other keymaps to prevent conflicts.
    – phils
    Commented Oct 28, 2014 at 3:24
  • Ah, so that's why ErgoEmacs uses a minor mode too. I thought it was too heavy weight for just a few keys, didn't think that it would also fix conflicts with other major modes. On the other hand, this way I get a closer look at each new mode and have to decide whether there are any of its keybindings that I should adopt into my scheme. :-) Commented Oct 28, 2014 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.