unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Alex Kost <alezost@gmail.com>
To: Rishabh Jain <rjain.ece@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Remapping navigation Keys in EMACS
Date: Tue, 11 Apr 2017 22:46:47 +0300	[thread overview]
Message-ID: <874lxubuc8.fsf@gmail.com> (raw)
In-Reply-To: <fafe5b9d-c544-a498-42bc-4c42fd897899@gmail.com> (Rishabh Jain's message of "Tue, 11 Apr 2017 13:53:50 -0400")

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	other threads:[~2017-04-11 19:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-11 17:53 Remapping navigation Keys in EMACS Rishabh Jain
2017-04-11 19:46 ` Alex Kost [this message]
2017-04-11 20:07 ` Stefan Huchler
2017-04-12 12:11   ` Rishabh Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874lxubuc8.fsf@gmail.com \
    --to=alezost@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rjain.ece@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).