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

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

Re: Modal Keyboard Layout for EMACS


From: Stefan Monnier
Subject: Re: Modal Keyboard Layout for EMACS
Date: Thu, 22 Nov 2012 18:21:10 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> I would like to write a small VI emulator for Emacs. By small, I mean
> really small. The source code should not go beyond 100 lines. I also
> need a better keyboard map than one can find in VIM. The ESC key
> should be replaced by a key that a typist can easily reach with the
> right hand.

The shortest code (a single line) might look something like:

   (viper-mode 1)

But I guess that's not what you mean.

> However, if I replace / slash for the square bracket, the program
> below does not work correctly. I mean, it ignores my remap of the /
> slash key.  If I press slash after replacing / slash for the
> occurrences of [ the program fails to enter normal command mode.

I don't see any obvious reason why that would be the case.  I suggest
you look at what C-h k / says to help you figure out what's going on.

I also appended my own take on the problem.


        Stefan


(defvar mvi-command-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "h" 'backward-char)
    (define-key map "j" 'next-line)
    (define-key map "k" 'previous-line)
    (define-key map "l" 'forward-char)
    (define-key map "i" 'mvi-insert-mode)
    (define-key map "/" 'mvi-doubled-self-insert-key)
    map))

(defun mvi-doubled-self-insert-key ()
  (interactive)
  (call-interactively 'self-insert-command)
  (mvi-insert-mode 1))
    
(define-minor-mode mvi-command-mode
  "Minimalistic VI-like mode."
  :lighter " <N>"
  :global t
  (if mvi-command-mode (mvi-normal-mode -1)))

(defvar mvi-command-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map "\e" 'mvi-command-mode)
    (define-key map "/"  'mvi-command-mode)
    map))

(define-minor-mode mvi-insert-mode
  "Normal Emacs editing mode with escape to VI mode."
  :lighter " <I>"
  :global t
  (if mvi-insert-mode (mvi-command-mode -1)))




reply via email to

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