Sunday, December 03, 2006

viper-mode in Emacs

Maybe you are disappointed at the cursor move around feature in Emacs and envy or miss the hjkl in vim.

But don't worry. There is a viper-mode in Emacs, which emulates vi behavioral in Emacs.
I have tried it. That is really attractive. It has added four states that are equivalent to VIM modes: Emacs-state, vi-state, insert-state and replace-state. Press C-z to toggle vi-state and emacs-state. Normally we don't need the Emacs-state when editing files, but it's still necessary for the major modes like info- and dired-mode that has lots of its own key bindings. We have all the powerful emacs features in insert-state, and meanwhile can move around conveniently in vi-state as in VIM.

Here is the installation of viper-mode. In ~/.emacs , add following lines:

(setq viper-mode t)
(require 'viper)
The configuration of viper-mode is stored in ~/.viper , add following lines:

(setq-default viper-mode t
viper-expert-level '5
;; ex-style don't allow you to move cross lines.
viper-ex-style-editing nil
viper-ex-style-motion nil
viper-auto-indent t
viper-inhibit-startup-message t
viper-eletric-mode t
viper-always t
viper-want-ctl-h-help t
viper-want-emacs-keys-in-insert t
viper-want-emacs-keys-in-vi t
viper-vi-style-in-minibuffer nil
viper-no-multiple-ESC t
viper-case-fold-search t
viper-re-search t
viper-re-query-replace t
viper-syntax-preference 'emacs
viper-delete-backwards-in-replace t
viper-parse-sexp-ignore-comments nil
viper-ESC-moves-cursor-back nil)

(define-key viper-vi-global-user-map "\C-f" 'forward-char)
(define-key viper-vi-global-user-map "\C-b" 'backward-char)
(define-key viper-vi-global-user-map "\M-v" 'scroll-down)
(define-key viper-vi-global-user-map "\C-v" 'scroll-up)
(define-key viper-vi-global-user-map "\C-y" 'yank)
(define-key viper-vi-global-user-map "\C-e"
(or (command-remapping 'move-end-of-line) 'move-end-of-line))

;; I don't like the default face in viper minibuffer
(setq viper-minibuffer-vi-face nil
viper-minibuffer-emacs-face nil)
del.icio.us Tags:

No comments: