help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remapping navigation Keys in EMACS


From: Alex Kost
Subject: Re: Remapping navigation Keys in EMACS
Date: Tue, 11 Apr 2017 22:46:47 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Rishabh Jain (2017-04-11 13:53 -0400) wrote:

> Hi:
>
> I'm just starting up with EMACS, and am curious if anyone has mapped
> their navigation keys (C-f,b,p,n, etc) to WASD format (like games do for
> navigation). If you have, please share your experience as well.
>
> W - up, A - left, S - down, D - right

I remap my navigation (as well as text editing, and many other) keys
similarly: E - up, S - left, D - down, F - right (actually, I use
".oeu" keys accordingly since I use Dvorak layout).

BTW, I wonder why WASD and not ESDF?  ESDF (I mean in "qwerty" layout)
is a natural position (especially for touch typing).  Ah, nevermind,
don't answer, tastes differ :-)

> Here's how I want to remap:
>
>  * C - (a,d) -> character wise left and right
>  * C - (w,s) -> line wise up and down
>  * M - (a,d) -> word wise left and right
>  * M - (w,s) -> paragraph wise up and down

Hey, I use the same key bindings! (except for the other (dvorak) keys).

>  * C - M - (a,d) -> (sentence wise left, right)
>  * C - M - (w,s) -> (move current line up/down)

Since most of the times I work with lisp-like languages, I use "C-M-..."
keys to navigate by sexps (like moving forward, backward, down, up) and
to edit them (kill backward, forward, transpose).  Nah, no one cares
what I use, sorry for bothering.

Other than that I had several hundreds of key bindings (maybe more than
a thousand including all the additional packages I use) :-)

> My biggest concern is that if this remapping would really impede my
> EMACS experience in time - for eg. using packages, etc.

Here is my experience: I was using "vanilla" Emacs keys for about a
year, then I realized that I can use much more ergonomic keys for basic
commands, and I began to rebind keys…  I spent a lot of time on this but
I was very pleased with the result (I've been using my remapped keys for
about 4 years).

Now, how you can bind your keys.  There are several ways and their
combinations to do that.  I'll mention 3 of them:

1. Rebind global keys (with 'global-set-key') and rebind the according
keys in all the keymaps of major and minor mode you use (with
'define-key').  This is a very time-consuming task, since all the
external packages follow the default Emacs key convention (e.g., n/p/f/b
keys for next / previous / forward / backward), and adjusting their
keymaps is a permanent process.

This is a "die hard" way and I don't recommend it unless you are going
to live in Emacs and you are obsessed on configuring every little thing.
I mention this way just because I use it :-)

2. Probably the easiest way to remap several keys is to make a minor mode.
There is a page about it: <https://www.emacswiki.org/emacs/esdf-mode>.
BTW Emacs wiki contains a lot of info about key bindings:
<https://www.emacswiki.org/emacs/CategoryKeys> (I've never read it
though).

Returning to that esdf-mode, I don't like how it is written, I would do
it like this:

--8<---------------cut here---------------start------------->8---
(defvar my-keys-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-a") 'backward-char)
    (define-key map (kbd "C-d") 'forward-char)
    (define-key map (kbd "C-w") 'previous-line)
    (define-key map (kbd "C-s") 'next-line)
    map))

(define-minor-mode my-keys-mode
  "Minor mode with the keys I use."
  :global t
  :init-value t
  :keymap my-keys-mode-map)
--8<---------------cut here---------------end--------------->8---

If you add the above code to your emacs config file, you'll get the key
bindings (some of them) you want.  You can always disable/enable this
mode with "M-x my-keys-mode".

3. Finally, there is "ergoemacs" package: <http://ergoemacs.github.io/>.
I've never tried it, but maybe it's what you want.

Oh well, I can write about key bindings much more, but I should stop :-)

-- 
Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]