The Road to Evil

Few years back, I've tried it but the transition experience still a lot to be desired. But due to the recent circumstance which piqued my interest to revisit this long overdue to-do item in my someday list again. Yes, to become an engaged member of the Church of Emacs.

Joke aside. With the recent development of Emacs and the more stable releases of its related plugins, the transition from Vim to Emacs seems doable and manageable. You still can retain most of the Vim experience in Emacs through Evil (Extensible Vi Layer for Emacs), but not without some additional customization. More on that in coming posts.

Installation in Ubuntu.
$ sudo apt-get install emacs24

$ emacs --version
GNU Emacs 24.5.1
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Well, this is Ubuntu/Debian, checking the emacs binary. Maybe there other Emacs implementations available?
$ file $(which emacs)
/usr/bin/emacs: symbolic link to /etc/alternatives/emacs

$ file /etc/alternatives/emacs 
/etc/alternatives/emacs: symbolic link to /usr/bin/emacs24-x

$ sudo update-alternatives --config emacs
There is only one alternative in link group emacs (providing /usr/bin/emacs): /usr/bin/emacs24-x
Nothing to configure.

By default, Emacs starts with X window system. If you want to bypass this behaviour and start in console instead, use the '-nw' parameter or add an alias instead.
$ emacs -nw
$ alias emc='emacs -nw'

Next is to install the Evil package for Emacs. If you need something up fast, check out the blog post by Bling and his Evil-mode bootstrap config. There is also a tutorial video to demonstrate evil-mode in Emacs. Ironically, I learned more about Vim than Emacs from his video.

To automatically install missing packages, the '.emacs.d/init.el` as follows.
$ cat .emacs.d/init.el 
; required packages
(setq package-list '(evil))

; additional repository
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))

; activate and refresh all the packages
(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

; install the missing packages
(dolist (package package-list)
  (unless (package-installed-p package)
    (package-install package)))

; enable evil-mode
(require 'evil)
(evil-mode 1)

Start Emacs in console but enable debugging. If there are no issues, Emacs will start normally and you can immediately start using it with Vim's default key bindings.
$ emacs -nw --debug-init

To prevent Repetitive strain injury (RSI), one the of way when using Vim is reducing your pinky or little finger usage. For the left pinky, the Escape (Esc) key and for the right pinky, the colon (:) key.

The Escape key.
This can be done by mapping 'jj' key to Escape key. Updates to our '.emacs.d/init.el' file.
$ cat init.el | grep "required\|exit" -A 3
; required packages
(setq package-list '(evil key-chord))

; additional repository
--
; exit insert mode by pressing j and then j quickly
(setq key-chord-two-keys-delay 0.5)
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
(key-chord-mode 1)

Binding the Colon (:) key.
This can be achieved by binding the colon (:) key to semicolon (;) key. Thus remove the needs to use the right Shift key. Changes to '.emacs.d/init.el' as shown again.
$ cat init.el | grep "evil-ex" -B 1
; bind ';' to ':'
(define-key evil-normal-state-map (kbd ";") 'evil-ex)

Restart Emacs and both settings should be customized to our liking.

As someone who suffered from RSI (rare these days but still prevention is still better than cure), these two customization are the essential minimum requirements for me to have a painless typing sessions. Not sure why, but both these settings should be the sensible default to Evil-mode, not enable by default, but should be part of the settings.

Stay tuned, expect more Emacs customization posts in coming months.

No comments:

Post a Comment