]> code.delx.au - gnu-emacs/blobdiff - lisp/emulation/vip.el
(add-log-buffer-file-name-function): Add defvar.
[gnu-emacs] / lisp / emulation / vip.el
index 6b38425d782deaa4256471cf0074e90751be23d1..51fbdb6b8c4f2e6f30ce1b09f135d432cf207232 100644 (file)
@@ -1,12 +1,32 @@
 ;;; vip.el --- a VI Package for GNU Emacs
 
+;; Copyright (C) 1986, 1987, 1988, 1992, 1993, 1998, 2002, 2003, 2004,
+;;   2005 Free Software Foundation, Inc.
+
 ;; Author: Masahiko Sato <ms@sail.stanford.edu>
-;; Version: 3.5
-;; Last-Modified: 15 Sep 1987
 ;; Keywords: emulations
 
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
 ;;; Commentary:
 
+;; A full-featured vi(1) emulator.
+;;
 ;; In Japan, the author's address is: masahiko@sato.riec.tohoku.junet
 ;;
 ;; Send suggestions and bug reports to one of the above addresses.
 
 ;;; Code:
 
+(defgroup vip nil
+  "A VI Package for GNU Emacs."
+  :prefix "vip-"
+  :group 'emulations)
+
 ;; external variables
 
 (defvar vip-emacs-local-map nil
-  "Local map used in emacs mode. \(buffer specific\)")
+  "Local map used in emacs mode.  (Buffer-specific.)")
 
 (defvar vip-insert-local-map nil
-  "Local map used in insert command mode. \(buffer specific\)")
-  
+  "Local map used in insert command mode.  (Buffer-specific.)")
+
 (make-variable-buffer-local 'vip-emacs-local-map)
 (make-variable-buffer-local 'vip-insert-local-map)
 
 (defvar vip-insert-point nil
-  "Remember insert point as a marker. \(buffer specific\)")
+  "Remember insert point as a marker.  (Buffer-specific.)")
 
 (set-default 'vip-insert-point (make-marker))
 (make-variable-buffer-local 'vip-insert-point)
 
 (defvar vip-com-point nil
-  "Remember com point as a marker. \(buffer specific\)")
+  "Remember com point as a marker.  (Buffer-specific.)")
 
 (set-default 'vip-com-point (make-marker))
 (make-variable-buffer-local 'vip-com-point)
 
 (defvar vip-current-mode nil
-  "Current mode.  One of emacs-mode, vi-mode, insert-mode.")
+  "Current mode.  One of `emacs-mode', `vi-mode', `insert-mode'.")
 
 (make-variable-buffer-local 'vip-current-mode)
 (setq-default vip-current-mode 'emacs-mode)
 
 (defvar vip-emacs-mode-line-buffer-identification nil
-  "value of mode-line-buffer-identification in emacs-mode.")
+  "Value of mode-line-buffer-identification in Emacs mode within vip.")
 (make-variable-buffer-local 'vip-emacs-mode-line-buffer-identification)
 (setq-default vip-emacs-mode-line-buffer-identification
              '("Emacs: %17b"))
 (make-variable-buffer-local 'vip-current-major-mode)
 
 (defvar vip-last-shell-com nil
-  "last shell command executed by ! command")
+  "Last shell command executed by ! command.")
 
 (defvar vip-use-register nil
-  "name of register to store deleted or yanked strings.")
+  "Name of register to store deleted or yanked strings.")
 
 (defvar vip-d-com nil
-  "If non-nil, it's value is a list (M-COM VAL COM), and is used to
-re-execute last destrcutive command")
+  "How to reexecute last destructive command.  Value is list (M-COM VAL COM).")
 
-(defconst vip-shift-width 8
-  "*The number of colums shifted by > and < command.")
+(defcustom vip-shift-width 8
+  "*The number of columns shifted by > and < command."
+  :type 'integer
+  :group 'vip)
 
-(defconst vip-re-replace nil
-  "*If t then do regexp replace, if nil then do string replace.")
+(defcustom vip-re-replace nil
+  "*If t then do regexp replace, if nil then do string replace."
+  :type 'boolean
+  :group 'vip)
 
 (defvar vip-d-char nil
-  "The character remenbered by the vi \"r\" command")
+  "The character remembered by the vi \"r\" command.")
 
 (defvar vip-f-char nil
-  "for use by \";\" command")
+  "For use by \";\" command.")
 
 (defvar vip-F-char nil
-  "for use by \".\" command")
+  "For use by \".\" command.")
 
 (defvar vip-f-forward nil
-  "for use by \";\" command")
-  
+  "For use by \";\" command.")
+
 (defvar vip-f-offset nil
-  "for use by \";\" command")
+  "For use by \";\" command.")
 
-(defconst vip-search-wrap-around t
-  "*if t, search wraps around")
+(defcustom vip-search-wrap-around t
+  "*If t, search wraps around."
+  :type 'boolean
+  :group 'vip)
 
-(defconst vip-re-search nil
-  "*if t, search is reg-exp search, otherwise vanilla search.")
+(defcustom vip-re-search nil
+  "*If t, search is reg-exp search, otherwise vanilla search."
+  :type 'boolean
+  :group 'vip)
 
 (defvar vip-s-string nil
-  "last search string")
+  "Last vip search string.")
 
 (defvar vip-s-forward nil
-  "if t, search is forward.")
+  "If t, search is forward.")
 
-(defconst vip-case-fold-search nil
-  "*if t, search ignores cases.")
+(defcustom vip-case-fold-search nil
+  "*If t, search ignores cases."
+  :type 'boolean
+  :group 'vip)
 
-(defconst vip-re-query-replace nil
-  "*If t then do regexp replace, if nil then do string replace.")
+(defcustom vip-re-query-replace nil
+  "*If t then do regexp replace, if nil then do string replace."
+  :type 'boolean
+  :group 'vip)
 
-(defconst vip-open-with-indent nil
-  "*if t, indent when open a new line.")
+(defcustom vip-open-with-indent nil
+  "*If t, indent when open a new line."
+  :type 'boolean
+  :group 'vip)
 
-(defconst vip-help-in-insert-mode nil
-  "*if t then C-h is bound to help-command in insert mode, if nil then it is
-bound to delete-backward-char.")
+(defcustom vip-help-in-insert-mode nil
+  "*If t then C-h is bound to help-command in insert mode.
+If nil then it is bound to `delete-backward-char'."
+  :type 'boolean
+  :group 'vip)
 
 (defvar vip-quote-string "> "
-  "string inserted at the beginning of region")
+  "String inserted at the beginning of region.")
 
 (defvar vip-tags-file-name "TAGS")
 
 (defvar vip-inhibit-startup-message nil)
+
+(defvar vip-startup-file (convert-standard-filename "~/.vip")
+  "Filename used as startup file for vip.")
+\f
+;; key bindings
+
+(defvar vip-mode-map (make-keymap))
+
+(define-key vip-mode-map "\C-a" 'beginning-of-line)
+(define-key vip-mode-map "\C-b" 'vip-scroll-back)
+(define-key vip-mode-map "\C-c" 'vip-ctl-c)
+(define-key vip-mode-map "\C-d" 'vip-scroll-up)
+(define-key vip-mode-map "\C-e" 'vip-scroll-up-one)
+(define-key vip-mode-map "\C-f" 'vip-scroll)
+(define-key vip-mode-map "\C-g" 'vip-keyboard-quit)
+(define-key vip-mode-map "\C-h" 'help-command)
+(define-key vip-mode-map "\C-m" 'vip-scroll-back)
+(define-key vip-mode-map "\C-n" 'vip-other-window)
+(define-key vip-mode-map "\C-o" 'vip-open-line-at-point)
+(define-key vip-mode-map "\C-u" 'vip-scroll-down)
+(define-key vip-mode-map "\C-x" 'vip-ctl-x)
+(define-key vip-mode-map "\C-y" 'vip-scroll-down-one)
+(define-key vip-mode-map "\C-z" 'vip-change-mode-to-emacs)
+(define-key vip-mode-map "\e" 'vip-ESC)
+
+(define-key vip-mode-map " " 'vip-scroll)
+(define-key vip-mode-map "!" 'vip-command-argument)
+(define-key vip-mode-map "\"" 'vip-command-argument)
+(define-key vip-mode-map "#" 'vip-command-argument)
+(define-key vip-mode-map "$" 'vip-goto-eol)
+(define-key vip-mode-map "%" 'vip-paren-match)
+(define-key vip-mode-map "&" 'vip-nil)
+(define-key vip-mode-map "'" 'vip-goto-mark-and-skip-white)
+(define-key vip-mode-map "(" 'vip-backward-sentence)
+(define-key vip-mode-map ")" 'vip-forward-sentence)
+(define-key vip-mode-map "*" 'call-last-kbd-macro)
+(define-key vip-mode-map "+" 'vip-next-line-at-bol)
+(define-key vip-mode-map "," 'vip-repeat-find-opposite)
+(define-key vip-mode-map "-" 'vip-previous-line-at-bol)
+(define-key vip-mode-map "." 'vip-repeat)
+(define-key vip-mode-map "/" 'vip-search-forward)
+
+(define-key vip-mode-map "0" 'vip-beginning-of-line)
+(define-key vip-mode-map "1" 'vip-digit-argument)
+(define-key vip-mode-map "2" 'vip-digit-argument)
+(define-key vip-mode-map "3" 'vip-digit-argument)
+(define-key vip-mode-map "4" 'vip-digit-argument)
+(define-key vip-mode-map "5" 'vip-digit-argument)
+(define-key vip-mode-map "6" 'vip-digit-argument)
+(define-key vip-mode-map "7" 'vip-digit-argument)
+(define-key vip-mode-map "8" 'vip-digit-argument)
+(define-key vip-mode-map "9" 'vip-digit-argument)
+
+(define-key vip-mode-map ":" 'vip-ex)
+(define-key vip-mode-map ";" 'vip-repeat-find)
+(define-key vip-mode-map "<" 'vip-command-argument)
+(define-key vip-mode-map "=" 'vip-command-argument)
+(define-key vip-mode-map ">" 'vip-command-argument)
+(define-key vip-mode-map "?" 'vip-search-backward)
+(define-key vip-mode-map "@" 'vip-nil)
+
+(define-key vip-mode-map "A" 'vip-Append)
+(define-key vip-mode-map "B" 'vip-backward-Word)
+(define-key vip-mode-map "C" 'vip-ctl-c-equivalent)
+(define-key vip-mode-map "D" 'vip-kill-line)
+(define-key vip-mode-map "E" 'vip-end-of-Word)
+(define-key vip-mode-map "F" 'vip-find-char-backward)
+(define-key vip-mode-map "G" 'vip-goto-line)
+(define-key vip-mode-map "H" 'vip-window-top)
+(define-key vip-mode-map "I" 'vip-Insert)
+(define-key vip-mode-map "J" 'vip-join-lines)
+(define-key vip-mode-map "K" 'vip-kill-buffer)
+(define-key vip-mode-map "L" 'vip-window-bottom)
+(define-key vip-mode-map "M" 'vip-window-middle)
+(define-key vip-mode-map "N" 'vip-search-Next)
+(define-key vip-mode-map "O" 'vip-Open-line)
+(define-key vip-mode-map "P" 'vip-Put-back)
+(define-key vip-mode-map "Q" 'vip-query-replace)
+(define-key vip-mode-map "R" 'vip-replace-string)
+(define-key vip-mode-map "S" 'vip-switch-to-buffer-other-window)
+(define-key vip-mode-map "T" 'vip-goto-char-backward)
+(define-key vip-mode-map "U" 'vip-nil)
+(define-key vip-mode-map "V" 'vip-find-file-other-window)
+(define-key vip-mode-map "W" 'vip-forward-Word)
+(define-key vip-mode-map "X" 'vip-ctl-x-equivalent)
+(define-key vip-mode-map "Y" 'vip-yank-line)
+(define-key vip-mode-map "ZZ" 'save-buffers-kill-emacs)
+
+(define-key vip-mode-map "[" 'vip-nil)
+(define-key vip-mode-map "\\" 'vip-escape-to-emacs)
+(define-key vip-mode-map "]" 'vip-nil)
+(define-key vip-mode-map "^" 'vip-bol-and-skip-white)
+(define-key vip-mode-map "_" 'vip-nil)
+(define-key vip-mode-map "`" 'vip-goto-mark)
+
+(define-key vip-mode-map "a" 'vip-append)
+(define-key vip-mode-map "b" 'vip-backward-word)
+(define-key vip-mode-map "c" 'vip-command-argument)
+(define-key vip-mode-map "d" 'vip-command-argument)
+(define-key vip-mode-map "e" 'vip-end-of-word)
+(define-key vip-mode-map "f" 'vip-find-char-forward)
+(define-key vip-mode-map "g" 'vip-info-on-file)
+(define-key vip-mode-map "h" 'vip-backward-char)
+(define-key vip-mode-map "i" 'vip-insert)
+(define-key vip-mode-map "j" 'vip-next-line)
+(define-key vip-mode-map "k" 'vip-previous-line)
+(define-key vip-mode-map "l" 'vip-forward-char)
+(define-key vip-mode-map "m" 'vip-mark-point)
+(define-key vip-mode-map "n" 'vip-search-next)
+(define-key vip-mode-map "o" 'vip-open-line)
+(define-key vip-mode-map "p" 'vip-put-back)
+(define-key vip-mode-map "q" 'vip-nil)
+(define-key vip-mode-map "r" 'vip-replace-char)
+(define-key vip-mode-map "s" 'vip-switch-to-buffer)
+(define-key vip-mode-map "t" 'vip-goto-char-forward)
+(define-key vip-mode-map "u" 'vip-undo)
+(define-key vip-mode-map "v" 'vip-find-file)
+(define-key vip-mode-map "w" 'vip-forward-word)
+(define-key vip-mode-map "x" 'vip-delete-char)
+(define-key vip-mode-map "y" 'vip-command-argument)
+(define-key vip-mode-map "zH" 'vip-line-to-top)
+(define-key vip-mode-map "zM" 'vip-line-to-middle)
+(define-key vip-mode-map "zL" 'vip-line-to-bottom)
+(define-key vip-mode-map "z\C-m" 'vip-line-to-top)
+(define-key vip-mode-map "z." 'vip-line-to-middle)
+(define-key vip-mode-map "z-" 'vip-line-to-bottom)
+
+(define-key vip-mode-map "{" 'vip-backward-paragraph)
+(define-key vip-mode-map "|" 'vip-goto-col)
+(define-key vip-mode-map "}" 'vip-forward-paragraph)
+(define-key vip-mode-map "~" 'vip-nil)
+(define-key vip-mode-map "\177" 'vip-delete-backward-char)
+
+(defun vip-version ()
+  (interactive)
+  (message "VIP version 3.5 of September 15, 1987"))
+
 \f
 ;; basic set up
 
-(global-set-key "\C-z" 'vip-change-mode-to-vi)
+;;;###autoload
+(defun vip-setup ()
+  "Set up bindings for C-x 7 and C-z that are useful for VIP users."
+  (define-key ctl-x-map "7" 'vip-buffer-in-two-windows)
+  (global-set-key "\C-z" 'vip-change-mode-to-vi))
 
 (defmacro vip-loop (count body)
   "(COUNT BODY) Execute BODY COUNT times."
@@ -135,7 +316,7 @@ bound to delete-backward-char.")
 (defun vip-push-mark-silent (&optional location)
   "Set mark at LOCATION (point, by default) and push old mark on mark ring.
 No message."
-  (if (null (mark))
+  (if (null (mark t))
       nil
     (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
     (if (> (length mark-ring) mark-ring-max)
@@ -157,10 +338,6 @@ No message."
     (forward-char (1- val))
     (if com (vip-execute-com 'vip-goto-col val com))))
 
-(defun vip-refresh-mode-line ()
-  "Redraw mode line."
-  (set-buffer-modified-p (buffer-modified-p)))
-
 (defun vip-copy-keymap (map)
   (if (null map) (make-sparse-keymap) (copy-keymap map)))
 
@@ -168,8 +345,7 @@ No message."
 ;; changing mode
 
 (defun vip-change-mode (new-mode)
-  "Change mode to NEW-MODE.  NEW-MODE is either emacs-mode, vi-mode,
-or insert-mode."
+  "Change mode to NEW-MODE---either emacs-mode, vi-mode, or insert-mode."
   (or (eq new-mode vip-current-mode)
       (progn
        (cond ((eq new-mode 'vi-mode)
@@ -203,11 +379,11 @@ or insert-mode."
                   'delete-backward-char))
               (define-key vip-insert-local-map "\C-w"
                 'vip-delete-backward-word))
-             ((eq new-mode 'emacs-mode) 
+             ((eq new-mode 'emacs-mode)
               (vip-change-mode-line "Emacs:")
               (use-local-map vip-emacs-local-map)))
        (setq vip-current-mode new-mode)
-       (vip-refresh-mode-line))))
+       (force-mode-line-update))))
 
 (defun vip-copy-region-as-kill (beg end)
   "If BEG and END do not belong to the same buffer, it copies empty region."
@@ -247,7 +423,8 @@ Type `n' to quit this window for now.\n")
            (progn
              (save-excursion
                (set-buffer
-                (find-file-noselect (substitute-in-file-name "~/.vip")))
+                (find-file-noselect
+                 (substitute-in-file-name vip-startup-file)))
                (goto-char (point-max))
                (insert "\n(setq vip-inhibit-startup-message t)\n")
                (save-buffer)
@@ -275,76 +452,21 @@ Type `n' to quit this window for now.\n")
   (vip-change-mode 'emacs-mode))
 
 \f
-;; escape to emacs mode termporarilly
-
-(defun vip-get-editor-command (l-map g-map &optional str)
-  "Read characters from keyboard until an editor command is formed, using
-local keymap L-MAP and global keymap G-MAP.  If the command is a
-self-insert-command, the character just read is returned instead.  Optional
-string STR is used as initial input string."
-  (let (char l-bind g-bind)
-    (setq char
-         (if (or (null str) (string= str ""))
-             (read-char)
-           (string-to-char str)))
-    (setq last-command-char char)
-    (setq l-bind (vip-binding-of char l-map))
-    (if (null l-bind)
-       ;; since local binding is empty, we concentrate on global one.
-       (progn
-         (setq g-bind (vip-binding-of char g-map))
-         (if (null g-bind)
-             nil ;; return nil, since both bindings are void.
-           (if (keymapp g-bind)
-               (vip-get-editor-command nil g-bind (vip-string-tail str))
-             (if (eq g-bind 'self-insert-command) char g-bind))))
-      ;; local binding is nonvoid
-      (if (keymapp l-bind)
-         ;; since l-bind is a keymap, we consider g-bind as well.
-         (progn
-           (setq g-bind (vip-binding-of char g-map))
-           (if (null g-bind)
-               (vip-get-editor-command l-bind nil (vip-string-tail str))
-             (if (keymapp g-bind)
-                 ;; both bindings are keymap
-                 (vip-get-editor-command l-bind g-bind (vip-string-tail str))
-               ;; l-bind is a keymap, so we neglect g-bind
-               (vip-get-editor-command l-bind nil (vip-string-tail str)))))
-       ;; l-bind is a command
-       (if (eq l-bind 'self-insert-command) char l-bind)))))
-
-(defun vip-binding-of (char map)
-  "Return key-binding of CHAR under keymap MAP.  It is nil if the binding
-is void, or a command, or a keymap"
-  (let ((val (if (listp map)
-                (cdr (assq char map))
-              (aref map char))))
-    (cond ((null val) nil)
-         ((keymapp val)
-          (if (symbolp val) (symbol-function val) val))
-         (t
-          ;; otherwise, it is a function which is either a real function or
-          ;; a keymap fset to val.
-          (let ((fun (symbol-function val)))
-            (if (or (null fun) (keymapp fun)) fun val))))))
-
-(defun vip-escape-to-emacs (arg &optional char)
-  "Escape to emacs mode and execute one emacs command and then return to
-vi mode.  ARG is used as the prefix value for the executed command.  If
-CHAR is given it becomes the first character of the command."
-  (interactive "P")
-  (let (com (buff (current-buffer)) (first t))
-    (if char (setq unread-command-char char))
+;; escape to emacs mode temporarily
+
+(defun vip-escape-to-emacs (arg &optional events)
+  "Escape to Emacs mode for one Emacs command.
+ARG is used as the prefix value for the executed command.  If
+EVENTS is a list of events, which become the beginning of the command."
+  (interactive "P")
+  (let (com key (old-map (current-local-map)))
+    (if events (setq unread-command-events events))
     (setq prefix-arg arg)
-    (while (or first (>= unread-command-char 0))
-      ;; this while loop is executed until unread command char will be
-      ;; exhausted.
-      (setq first nil)
-      (setq com (vip-get-editor-command vip-emacs-local-map global-map))
-      (if (numberp com)
-         (vip-loop (vip-p-val prefix-arg)
-                   (insert (char-to-string com)))
-       (command-execute com prefix-arg)))
+    (use-local-map vip-emacs-local-map)
+    (unwind-protect
+       (setq com (key-binding (setq key (read-key-sequence nil))))
+      (use-local-map old-map))
+    (command-execute com prefix-arg)
     (setq prefix-arg nil)  ;; reset prefix arg
     ))
 
@@ -359,25 +481,25 @@ CHAR is given it becomes the first character of the command."
 (defun vip-ESC (arg)
   "Emulate ESC key in Emacs mode."
   (interactive "P")
-  (vip-escape-to-emacs arg ?\e))
+  (vip-escape-to-emacs arg '(?\e)))
 
 (defun vip-ctl-c (arg)
   "Emulate C-c key in Emacs mode."
   (interactive "P")
-  (vip-escape-to-emacs arg ?\C-c))
+  (vip-escape-to-emacs arg '(?\C-c)))
 
 (defun vip-ctl-x (arg)
   "Emulate C-x key in Emacs mode."
   (interactive "P")
-  (vip-escape-to-emacs arg ?\C-x))
+  (vip-escape-to-emacs arg '(?\C-x)))
 
 (defun vip-ctl-h (arg)
   "Emulate C-h key in Emacs mode."
   (interactive "P")
-  (vip-escape-to-emacs arg ?\C-h))
+  (vip-escape-to-emacs arg '(?\C-h)))
 
 \f
-;; prefix argmument for vi mode
+;; prefix argument for vi mode
 
 ;; In vi mode, prefix argument is a dotted pair (NUM . COM) where NUM
 ;; represents the numeric value of the prefix argument and COM represents
@@ -387,14 +509,14 @@ CHAR is given it becomes the first character of the command."
   "Compute numeric prefix arg value.  Invoked by CHAR.  VALUE is the value
 obtained so far, and COM is the command part obtained so far."
   (while (and (>= char ?0) (<= char ?9))
-    (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)))       
+    (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)))
     (setq char (read-char)))
   (setq prefix-arg value)
   (if com (setq prefix-arg (cons prefix-arg com)))
   (while (= char ?U)
     (vip-describe-arg prefix-arg)
     (setq char (read-char)))
-  (setq unread-command-char char))
+  (setq unread-command-events (list char)))
 
 (defun vip-prefix-arg-com (char value com)
   "Vi operator as prefix argument."
@@ -414,7 +536,7 @@ obtained so far, and COM is the command part obtained so far."
            (setq cont nil))
        ;; if com is nil we set com as char, and read more.  again, if char
        ;; is ", we read the name of register and store it in vip-use-register.
-       ;; if char is !, =, or #, a copmlete com is formed so we exit while.
+       ;; if char is !, =, or #, a complete com is formed so we exit while.
        (cond ((or (= char ?!) (= char ?=))
               (setq com char)
               (setq char (read-char))
@@ -440,7 +562,7 @@ obtained so far, and COM is the command part obtained so far."
               (setq com char)
               (setq char (read-char)))))))
   (if (atom com)
-      ;; com is a single char, so we construct prefix-arg 
+      ;; com is a single char, so we construct prefix-arg
       ;; and if char is ?, describe prefix arg, otherwise exit by
       ;; pushing the char back
       (progn
@@ -448,10 +570,10 @@ obtained so far, and COM is the command part obtained so far."
        (while (= char ?U)
          (vip-describe-arg prefix-arg)
          (setq char (read-char)))
-       (setq unread-command-char char))
+       (setq unread-command-events (list char)))
     ;; as com is non-nil, this means that we have a command to execute
     (if (or (= (car com) ?r) (= (car com) ?R))
-       ;; execute apropriate region command.
+       ;; execute appropriate region command.
        (let ((char (car com)) (com (cdr com)))
          (setq prefix-arg (cons value com))
          (if (= char ?r) (vip-region prefix-arg)
@@ -477,7 +599,7 @@ obtained so far, and COM is the command part obtained so far."
          com (vip-getcom arg))
     (if (null val)
        (if (null com)
-           (message "Value is nil, and commmand is nil.")
+           (message "Value is nil, and command is nil.")
          (message "Value is nil, and command is %c." com))
       (if (null com)
          (message "Value is %d, and command is nil." val)
@@ -494,7 +616,7 @@ obtained so far, and COM is the command part obtained so far."
   (interactive "P")
   (condition-case conditions
       (vip-prefix-arg-com
-       last-command-char   
+       last-command-char
        (cond ((null arg) nil)
             ((consp arg) (car arg))
             ((numberp arg) arg)
@@ -681,8 +803,8 @@ to vip-d-com for later use by vip-repeat"
                          reg))))
 
 (defun vip-repeat (arg)
-  "(ARG)  Re-excute last destructive command.  vip-d-com has the form
-(COM ARG CH REG), where COM is the command to be re-executed, ARG is the
+  "(ARG)  Re-execute last destructive command.  vip-d-com has the form
+\(COM ARG CH REG), where COM is the command to be re-executed, ARG is the
 argument for COM, CH is a flag for repeat, and REG is optional and if exists
 is the name of the register for COM."
   (interactive "P")
@@ -696,7 +818,7 @@ is the name of the register for COM."
          (com (car (cdr (cdr vip-d-com))))
          (reg (nth 3 vip-d-com)))
       (if (null val) (setq val (car (cdr vip-d-com))))
-      (if (null m-com) (error "No previous command to repeat."))
+      (if (null m-com) (error "No previous command to repeat"))
       (setq vip-use-register reg)
       (funcall m-com (cons val com)))))
 
@@ -786,11 +908,13 @@ each line in the region."
 
 (defun vip-end-with-a-newline-p (string)
   "Check if the string ends with a newline."
-  (or (string= text "")
+  (or (string= string "")
       (= (aref string (1- (length string))) ?\n)))
 
+(defvar vip-save-minibuffer-local-map)
+
 (defun vip-read-string (prompt &optional init)
-  (setq save-minibuffer-local-map (copy-keymap minibuffer-local-map))
+  (setq vip-save-minibuffer-local-map (copy-keymap minibuffer-local-map))
   (define-key minibuffer-local-map "\C-h" 'backward-char)
   (define-key minibuffer-local-map "\C-w" 'backward-word)
   (define-key minibuffer-local-map "\e" 'exit-minibuffer)
@@ -798,9 +922,9 @@ each line in the region."
     (condition-case conditions
        (setq str (read-string prompt init))
       (quit
-       (setq minibuffer-local-map save-minibuffer-local-map)
+       (setq minibuffer-local-map vip-save-minibuffer-local-map)
        (signal 'quit nil)))
-    (setq minibuffer-local-map save-minibuffer-local-map)
+    (setq minibuffer-local-map vip-save-minibuffer-local-map)
     str))
 
 \f
@@ -812,7 +936,7 @@ vi command mode.  It will repeat the insertion command if original insertion
 command was invoked with argument > 1."
   (let ((i-com (car vip-d-com)) (val (car (cdr vip-d-com))))
     (if (and val (> val 1)) ;; first check that val is non-nil
-       (progn        
+       (progn
          (setq vip-d-com (list i-com (1- val) ?r))
          (vip-repeat nil)
          (setq vip-d-com (list i-com val ?r))))))
@@ -914,7 +1038,7 @@ command was invoked with argument > 1."
          (vip-change-subr (mark) (point))
        (vip-change (mark) (point))))
     (setq vip-d-com (list 'vip-substitute val ?r))))
-  
+
 (defun vip-substitute-line (arg)
   "Substitute lines."
   (interactive "p")
@@ -934,7 +1058,7 @@ command was invoked with argument > 1."
   (interactive "P")
   (let ((val (vip-p-val arg)))
     (vip-line (cons val ?Y))))
-    
+
 \f
 ;; region command
 
@@ -953,7 +1077,7 @@ command was invoked with argument > 1."
     (move-marker vip-com-point (point))
     (exchange-point-and-mark)
     (vip-execute-com 'vip-Region val com)))
-  
+
 (defun vip-replace-char (arg)
   "Replace the following ARG chars by the character read."
   (interactive "P")
@@ -977,16 +1101,21 @@ the query replace mode will toggle between string replace and regexp replace."
     (if (string= str "")
        (progn
          (setq vip-re-replace (not vip-re-replace))
-         (message (format "Replace mode changed to %s."
-                          (if vip-re-replace "regexp replace"
-                            "string replace"))))
+         (message "Replace mode changed to %s."
+                  (if vip-re-replace "regexp replace"
+                    "string replace")))
       (if vip-re-replace
-         (replace-regexp
+         ;; (replace-regexp
+         ;;  str
+         ;;  (vip-read-string (format "Replace regexp \"%s\" with: " str)))
+         (while (re-search-forward str nil t)
+           (replace-match (vip-read-string
+                           (format "Replace regexp \"%s\" with: " str))
+                          nil nil))
+       (with-no-warnings
+         (replace-string
           str
-          (vip-read-string (format "Replace regexp \"%s\" with: " str)))
-       (replace-string
-        str
-        (vip-read-string (format "Replace \"%s\" with: " str)))))))
+          (vip-read-string (format "Replace \"%s\" with: " str))))))))
 
 \f
 ;; basic cursor movement.  j, k, l, m commands.
@@ -1044,7 +1173,7 @@ beginning of buffer, stop and signal error."
        (progn
          (forward-char)
          (vip-execute-com 'vip-end-of-word val com)))))
-                        
+
 (defun vip-backward-word (arg)
   "Backward word."
   (interactive "P")
@@ -1183,7 +1312,7 @@ beginning of buffer, stop and signal error."
     (if com (vip-execute-com 'vip-goto-line val com))))
 
 (defun vip-find-char (arg char forward offset)
-  "Find ARG's occurence of CHAR on the current line.  If FORWARD then
+  "Find ARG's occurrence of CHAR on the current line.  If FORWARD then
 search is forward, otherwise backward.  OFFSET is used to adjust point
 after search."
   (let ((arg (if forward arg (- arg))) point)
@@ -1214,7 +1343,7 @@ after search."
 (defun vip-find-char-forward (arg)
   "Find char on the line.  If called interactively read the char to find
 from the terminal, and if called from vip-repeat, the char last used is
-used.  This behaviour is controlled by the sign of prefix numeric value."
+used.  This behavior is controlled by the sign of prefix numeric value."
   (interactive "P")
   (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
     (if (> val 0)
@@ -1372,7 +1501,7 @@ used.  This behaviour is controlled by the sign of prefix numeric value."
   (let ((com (vip-getcom arg)))
     (if (numberp arg)
        (if (or (> arg 99) (< arg 1))
-           (error "Prefix must be between 1 and 99.")
+           (error "Prefix must be between 1 and 99")
          (goto-char
           (if (> (point-max) 80000)
               (* (/ (point-max) 100) arg)
@@ -1484,7 +1613,7 @@ used.  This behaviour is controlled by the sign of prefix numeric value."
 ;; searching
 
 (defun vip-search-forward (arg)
-  "Search a string forward.  ARG is used to find the ARG's occurence
+  "Search a string forward.  ARG is used to find the ARG's occurrence
 of the string.  Default is vanilla search.  Search mode can be toggled by
 giving null search string."
   (interactive "P")
@@ -1494,9 +1623,9 @@ giving null search string."
     (if (string= vip-s-string "")
        (progn
          (setq vip-re-search (not vip-re-search))
-         (message (format "Search mode changed to %s search."
-                          (if vip-re-search "regular expression"
-                            "vanilla"))))
+         (message "Search mode changed to %s search."
+                  (if vip-re-search "regular expression"
+                    "vanilla")))
       (vip-search vip-s-string t val)
       (if com
          (progn
@@ -1504,7 +1633,7 @@ giving null search string."
            (vip-execute-com 'vip-search-next val com))))))
 
 (defun vip-search-backward (arg)
-  "Search a string backward.  ARG is used to find the ARG's occurence
+  "Search a string backward.  ARG is used to find the ARG's occurrence
 of the string.  Default is vanilla search.  Search mode can be toggled by
 giving null search string."
   (interactive "P")
@@ -1514,9 +1643,9 @@ giving null search string."
     (if (string= vip-s-string "")
        (progn
          (setq vip-re-search (not vip-re-search))
-         (message (format "Search mode changed to %s search."
-                          (if vip-re-search "regular expression"
-                            "vanilla"))))
+         (message "Search mode changed to %s search."
+                  (if vip-re-search "regular expression"
+                    "vanilla")))
       (vip-search vip-s-string nil val)
       (if com
          (progn
@@ -1566,7 +1695,7 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
   "Repeat previous search."
   (interactive "P")
   (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
-    (if (null vip-s-string) (error "No previous search string."))
+    (if (null vip-s-string) (error "No previous search string"))
     (vip-search vip-s-string vip-s-forward arg)
     (if com (vip-execute-com 'vip-search-next val com))))
 
@@ -1574,7 +1703,7 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
   "Repeat previous search in the reverse direction."
   (interactive "P")
   (let ((val (vip-p-val arg)) (com (vip-getcom arg)))
-    (if (null vip-s-string) (error "No previous search string."))
+    (if (null vip-s-string) (error "No previous search string"))
     (vip-search vip-s-string (not vip-s-forward) arg)
     (if com (vip-execute-com 'vip-search-Next val com))))
 
@@ -1615,11 +1744,11 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
          (if (null buffer-name)
              (current-buffer)
            (get-buffer buffer-name)))
-    (if (null buffer) (error "Buffer %s nonexistent." buffer-name))
+    (if (null buffer) (error "Buffer %s nonexistent" buffer-name))
     (if (or (not (buffer-modified-p buffer))
            (y-or-n-p "Buffer is modified, are you sure? "))
        (kill-buffer buffer)
-      (error "Buffer not killed."))))
+      (error "Buffer not killed"))))
 
 (defun vip-find-file ()
   "Visit file in the current window."
@@ -1709,7 +1838,7 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
        (progn
          (if (and (<= ?A vip-use-register) (<= vip-use-register ?Z))
              (vip-append-to-register
-              (+ vip-use-register 32) (point) (- (point) val) nil)
+              (+ vip-use-register 32) (point) (- (point) val))
            (copy-to-register vip-use-register (point) (- (point) val) nil))
          (setq vip-use-register nil)))
     (delete-char val t)))
@@ -1723,7 +1852,7 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
        (progn
          (if (and (<= ?A vip-use-register) (<= vip-use-register ?Z))
              (vip-append-to-register
-              (+ vip-use-register 32) (point) (+ (point) val) nil)
+              (+ vip-use-register 32) (point) (+ (point) val))
            (copy-to-register vip-use-register (point) (+ (point) val) nil))
          (setq vip-use-register nil)))
     (delete-backward-char val t)))
@@ -1748,8 +1877,10 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
 \f
 ;; making small changes
 
+(defvar vip-c-string)
+
 (defun vip-change (beg end)
-  (setq c-string
+  (setq vip-c-string
        (vip-read-string (format "%s => " (buffer-substring beg end))))
   (vip-change-subr beg end))
 
@@ -1760,7 +1891,7 @@ STRING.  Search will be forward if FORWARD, otherwise backward."
        (setq vip-use-register nil)))
   (kill-region beg end)
   (setq this-command 'vip-change)
-  (insert c-string))
+  (insert vip-c-string))
 
 \f
 ;; query replace
@@ -1807,7 +1938,7 @@ the query replace mode will toggle between string replace and regexp replace."
 (defun vip-mark-point (char)
   (interactive "c")
   (cond ((and (<= ?a char) (<= char ?z))
-        (point-to-register (- char (- ?a ?\C-a))))
+        (point-to-register (- char (- ?a ?\C-a)) nil))
        ((= char ?<) (vip-mark-beginning-of-buffer))
        ((= char ?>) (vip-mark-end-of-buffer))
        ((= char ?.) (push-mark))
@@ -1880,12 +2011,7 @@ the query replace mode will toggle between string replace and regexp replace."
   (let ((char (read-char)))
     (if (and (<= ?A char) (<= char ?Z))
        (setq char (- char (- ?A ?\C-a))))
-         (setq prefix-arg arg)
-         (command-execute
-          (vip-get-editor-command
-           vip-emacs-local-map global-map
-           (format "%s%s" key (char-to-string char))))))
-  
+    (vip-escape-to-emacs arg (list (aref key 0) char))))
 \f
 ;; commands in insertion mode
 
@@ -1897,143 +2023,6 @@ the query replace mode will toggle between string replace and regexp replace."
     (backward-word arg)
     (delete-region (point) (mark))))
 
-\f
-;; key bindings
-
-(set 'vip-mode-map (make-keymap))
-
-(define-key vip-mode-map "\C-a" 'beginning-of-line)
-(define-key vip-mode-map "\C-b" 'vip-scroll-back)
-(define-key vip-mode-map "\C-c" 'vip-ctl-c)
-(define-key vip-mode-map "\C-d" 'vip-scroll-up)
-(define-key vip-mode-map "\C-e" 'vip-scroll-up-one)
-(define-key vip-mode-map "\C-f" 'vip-scroll)
-(define-key vip-mode-map "\C-g" 'vip-keyboard-quit)
-(define-key vip-mode-map "\C-h" 'help-command)
-(define-key vip-mode-map "\C-m" 'vip-scroll-back)
-(define-key vip-mode-map "\C-n" 'vip-other-window)
-(define-key vip-mode-map "\C-o" 'vip-open-line-at-point)
-(define-key vip-mode-map "\C-u" 'vip-scroll-down)
-(define-key vip-mode-map "\C-x" 'vip-ctl-x)
-(define-key vip-mode-map "\C-y" 'vip-scroll-down-one)
-(define-key vip-mode-map "\C-z" 'vip-change-mode-to-emacs)
-(define-key vip-mode-map "\e" 'vip-ESC)
-
-(define-key vip-mode-map " " 'vip-scroll)
-(define-key vip-mode-map "!" 'vip-command-argument)
-(define-key vip-mode-map "\"" 'vip-command-argument)
-(define-key vip-mode-map "#" 'vip-command-argument)
-(define-key vip-mode-map "$" 'vip-goto-eol)
-(define-key vip-mode-map "%" 'vip-paren-match)
-(define-key vip-mode-map "&" 'vip-nil)
-(define-key vip-mode-map "'" 'vip-goto-mark-and-skip-white)
-(define-key vip-mode-map "(" 'vip-backward-sentence)
-(define-key vip-mode-map ")" 'vip-forward-sentence)
-(define-key vip-mode-map "*" 'call-last-kbd-macro)
-(define-key vip-mode-map "+" 'vip-next-line-at-bol)
-(define-key vip-mode-map "," 'vip-repeat-find-opposite)
-(define-key vip-mode-map "-" 'vip-previous-line-at-bol)
-(define-key vip-mode-map "." 'vip-repeat)
-(define-key vip-mode-map "/" 'vip-search-forward)
-
-(define-key vip-mode-map "0" 'vip-beginning-of-line)
-(define-key vip-mode-map "1" 'vip-digit-argument)
-(define-key vip-mode-map "2" 'vip-digit-argument)
-(define-key vip-mode-map "3" 'vip-digit-argument)
-(define-key vip-mode-map "4" 'vip-digit-argument)
-(define-key vip-mode-map "5" 'vip-digit-argument)
-(define-key vip-mode-map "6" 'vip-digit-argument)
-(define-key vip-mode-map "7" 'vip-digit-argument)
-(define-key vip-mode-map "8" 'vip-digit-argument)
-(define-key vip-mode-map "9" 'vip-digit-argument)
-
-(define-key vip-mode-map ":" 'vip-ex)
-(define-key vip-mode-map ";" 'vip-repeat-find)
-(define-key vip-mode-map "<" 'vip-command-argument)
-(define-key vip-mode-map "=" 'vip-command-argument)
-(define-key vip-mode-map ">" 'vip-command-argument)
-(define-key vip-mode-map "?" 'vip-search-backward)
-(define-key vip-mode-map "@" 'vip-nil)
-
-(define-key vip-mode-map "A" 'vip-Append)
-(define-key vip-mode-map "B" 'vip-backward-Word)
-(define-key vip-mode-map "C" 'vip-ctl-c-equivalent)
-(define-key vip-mode-map "D" 'vip-kill-line)
-(define-key vip-mode-map "E" 'vip-end-of-Word)
-(define-key vip-mode-map "F" 'vip-find-char-backward)
-(define-key vip-mode-map "G" 'vip-goto-line)
-(define-key vip-mode-map "H" 'vip-window-top)
-(define-key vip-mode-map "I" 'vip-Insert)
-(define-key vip-mode-map "J" 'vip-join-lines)
-(define-key vip-mode-map "K" 'vip-kill-buffer)
-(define-key vip-mode-map "L" 'vip-window-bottom)
-(define-key vip-mode-map "M" 'vip-window-middle)
-(define-key vip-mode-map "N" 'vip-search-Next)
-(define-key vip-mode-map "O" 'vip-Open-line)
-(define-key vip-mode-map "P" 'vip-Put-back)
-(define-key vip-mode-map "Q" 'vip-query-replace)
-(define-key vip-mode-map "R" 'vip-replace-string)
-(define-key vip-mode-map "S" 'vip-switch-to-buffer-other-window)
-(define-key vip-mode-map "T" 'vip-goto-char-backward)
-(define-key vip-mode-map "U" 'vip-nil)
-(define-key vip-mode-map "V" 'vip-find-file-other-window)
-(define-key vip-mode-map "W" 'vip-forward-Word)
-(define-key vip-mode-map "X" 'vip-ctl-x-equivalent)
-(define-key vip-mode-map "Y" 'vip-yank-line)
-(define-key vip-mode-map "ZZ" 'save-buffers-kill-emacs)
-
-(define-key vip-mode-map "[" 'vip-nil)
-(define-key vip-mode-map "\\" 'vip-escape-to-emacs)
-(define-key vip-mode-map "]" 'vip-nil)
-(define-key vip-mode-map "^" 'vip-bol-and-skip-white)
-(define-key vip-mode-map "_" 'vip-nil)
-(define-key vip-mode-map "`" 'vip-goto-mark)
-
-(define-key vip-mode-map "a" 'vip-append)
-(define-key vip-mode-map "b" 'vip-backward-word)
-(define-key vip-mode-map "c" 'vip-command-argument)
-(define-key vip-mode-map "d" 'vip-command-argument)
-(define-key vip-mode-map "e" 'vip-end-of-word)
-(define-key vip-mode-map "f" 'vip-find-char-forward)
-(define-key vip-mode-map "g" 'vip-info-on-file)
-(define-key vip-mode-map "h" 'vip-backward-char)
-(define-key vip-mode-map "i" 'vip-insert)
-(define-key vip-mode-map "j" 'vip-next-line)
-(define-key vip-mode-map "k" 'vip-previous-line)
-(define-key vip-mode-map "l" 'vip-forward-char)
-(define-key vip-mode-map "m" 'vip-mark-point)
-(define-key vip-mode-map "n" 'vip-search-next)
-(define-key vip-mode-map "o" 'vip-open-line)
-(define-key vip-mode-map "p" 'vip-put-back)
-(define-key vip-mode-map "q" 'vip-nil)
-(define-key vip-mode-map "r" 'vip-replace-char)
-(define-key vip-mode-map "s" 'vip-switch-to-buffer)
-(define-key vip-mode-map "t" 'vip-goto-char-forward)
-(define-key vip-mode-map "u" 'vip-undo)
-(define-key vip-mode-map "v" 'vip-find-file)
-(define-key vip-mode-map "w" 'vip-forward-word)
-(define-key vip-mode-map "x" 'vip-delete-char)
-(define-key vip-mode-map "y" 'vip-command-argument)
-(define-key vip-mode-map "zH" 'vip-line-to-top)
-(define-key vip-mode-map "zM" 'vip-line-to-middle)
-(define-key vip-mode-map "zL" 'vip-line-to-bottom)
-(define-key vip-mode-map "z\C-m" 'vip-line-to-top)
-(define-key vip-mode-map "z." 'vip-line-to-middle)
-(define-key vip-mode-map "z-" 'vip-line-to-bottom)
-
-(define-key vip-mode-map "{" 'vip-backward-paragraph)
-(define-key vip-mode-map "|" 'vip-goto-col)
-(define-key vip-mode-map "}" 'vip-forward-paragraph)
-(define-key vip-mode-map "~" 'vip-nil)
-(define-key vip-mode-map "\177" 'vip-delete-backward-char)
-
-(define-key ctl-x-map "3" 'vip-buffer-in-two-windows)
-(define-key ctl-x-map "\C-i" 'insert-file)
-
-(defun vip-version ()
-  (interactive)
-  (message "VIP version 3.5 of September 15, 1987"))
-
 \f
 ;; implement ex commands
 
@@ -2072,7 +2061,7 @@ is a command.")
   "pattern for global command")
 
 (defvar ex-map (make-sparse-keymap)
-  "save commnads for mapped keys")
+  "save commands for mapped keys")
 
 (defvar ex-tag nil
   "save ex tag")
@@ -2189,7 +2178,7 @@ a token has type \(command, address, end-mark\) and value."
                 (cond ((string= ex-token-type "plus") "add-number")
                       ((string= ex-token-type "minus") "sub-number")
                       (t "abs-number")))
-          (setq ex-token (string-to-int (buffer-substring (point) (mark)))))
+          (setq ex-token (string-to-number (buffer-substring (point) (mark)))))
          ((looking-at "\\$")
           (forward-char 1)
           (setq ex-token-type "end"))
@@ -2265,7 +2254,7 @@ a token has type \(command, address, end-mark\) and value."
           (setq ex-token-type "end-mark")
           (setq ex-token "goto"))
          (t
-          (error "illegal token")))))
+          (error "invalid token")))))
 
 (defun vip-ex (&optional string)
   "ex commands within VIP."
@@ -2304,7 +2293,7 @@ a token has type \(command, address, end-mark\) and value."
                             (setq cont nil))
                            (t (error "Extra character at end of a command")))))))
            ((string= ex-token-type "non-command")
-            (error (format "%s: Not an editor command" ex-token)))
+            (error "%s: Not an editor command" ex-token))
            ((string= ex-token-type "whole")
             (setq ex-addresses
                   (cons (point-max) (cons (point-min) ex-addresses))))
@@ -2483,14 +2472,14 @@ a token has type \(command, address, end-mark\) and value."
        (progn
          (set-mark (point))
          (re-search-forward "[0-9][0-9]*")
-         (setq ex-count (string-to-int (buffer-substring (point) (mark))))
+         (setq ex-count (string-to-number (buffer-substring (point) (mark))))
          (skip-chars-forward " \t")))
     (if (looking-at "[pl#]")
        (progn
          (setq ex-flag t)
          (forward-char 1)))
     (if (not (looking-at "[\n|]"))
-       (error "Illegal extra characters"))))
+       (error "Invalid extra characters"))))
 
 (defun vip-get-ex-count ()
   (setq ex-variant nil
@@ -2508,14 +2497,14 @@ a token has type \(command, address, end-mark\) and value."
        (progn
          (set-mark (point))
          (re-search-forward "[0-9][0-9]*")
-         (setq ex-count (string-to-int (buffer-substring (point) (mark))))
+         (setq ex-count (string-to-number (buffer-substring (point) (mark))))
          (skip-chars-forward " \t")))
     (if (looking-at "[pl#]")
        (progn
          (setq ex-flag t)
          (forward-char 1)))
     (if (not (looking-at "[\n|]"))
-       (error "Illegal extra characters"))))
+       (error "Invalid extra characters"))))
 
 (defun vip-get-ex-file ()
   "get a file name and set ex-variant, ex-append and ex-offset if found"
@@ -2593,7 +2582,7 @@ a token has type \(command, address, end-mark\) and value."
             (string= ex-token "insert")
             (string= ex-token "open")
             )
-        (error (format "%s: no such command from VIP" ex-token)))
+        (error "%s: no such command from VIP" ex-token))
        ((or (string= ex-token "abbreviate")
             (string= ex-token "list")
             (string= ex-token "next")
@@ -2606,8 +2595,8 @@ a token has type \(command, address, end-mark\) and value."
             (string= ex-token "xit")
             (string= ex-token "z")
             )
-        (error (format "%s: not implemented in VIP" ex-token)))
-       (t (error (format "%s: Not an editor command" ex-token)))))
+        (error "%s: not implemented in VIP" ex-token))
+       (t (error "%s: Not an editor command" ex-token))))
 
 (defun ex-goto ()
   "ex goto command"
@@ -2677,7 +2666,7 @@ a token has type \(command, address, end-mark\) and value."
        (if ex-buffer
            (if (and (<= ?A ex-buffer) (<= ex-buffer ?Z))
                (vip-append-to-register
-                (+ ex-buffer 32) (point) (mark) nil)
+                (+ ex-buffer 32) (point) (mark))
              (copy-to-register ex-buffer (point) (mark) nil)))
        (delete-region (point) (mark))))))
 
@@ -2829,7 +2818,7 @@ a token has type \(command, address, end-mark\) and value."
          (error "Mark must specify a letter"))))
     (save-excursion
       (goto-char (car ex-addresses))
-      (point-to-register (- char (- ?a ?\C-a))))))
+      (point-to-register (- char (- ?a ?\C-a)) nil))))
 
 (defun ex-map ()
   "ex map"
@@ -2842,7 +2831,8 @@ a token has type \(command, address, end-mark\) and value."
       (skip-chars-forward " \t")
       (if (looking-at "[\n|]") (error "Missing rhs"))
       (set-mark (point))
-      (end-of-buffer)
+      (with-no-warnings
+       (end-of-buffer))
       (backward-char 1)
       (setq string (buffer-substring (mark) (point))))
     (if (not (lookup-key ex-map char))
@@ -2912,7 +2902,8 @@ a token has type \(command, address, end-mark\) and value."
        (setq file (buffer-substring (point) (mark)))))
       (if variant
          (shell-command command t)
-       (insert-file file))))
+       (with-no-warnings
+         (insert-file file)))))
 
 (defun ex-set ()
   (eval (list 'setq
@@ -2924,8 +2915,9 @@ a token has type \(command, address, end-mark\) and value."
   (vip-change-mode-to-emacs)
   (shell))
 
-(defun ex-substitute (&optional repeat r-flag) 
-  "ex substitute. if REPEAT use previous reg-exp which is ex-reg-exp or
+(defun ex-substitute (&optional repeat r-flag)
+  "ex substitute.
+If REPEAT use previous reg-exp which is ex-reg-exp or
 vip-s-string"
   (let (pat repl (opt-g nil) (opt-c nil) (matched-pos nil))
     (if repeat (setq ex-token nil) (vip-get-ex-pat))
@@ -3022,7 +3014,7 @@ vip-s-string"
   (if (and (not (string= ex-file (buffer-file-name)))
           (file-exists-p ex-file)
           (not ex-variant))
-      (error (format "\"%s\" File exists - use w! to override" ex-file)))
+      (error "\"%s\" File exists - use w! to override" ex-file))
   (let ((end (car ex-addresses)) (beg (car (cdr ex-addresses))))
     (if (> beg end) (error "First address exceeds second"))
     (save-excursion
@@ -3047,7 +3039,7 @@ vip-s-string"
            (forward-line (1- ex-count)))
        (set-mark end))
       (vip-enlarge-region (point) (mark))
-      (if ex-flag (error "Extra chacters at end of command"))
+      (if ex-flag (error "Extra characters at end of command"))
       (if ex-buffer
          (copy-to-register ex-buffer (point) (mark) nil))
       (copy-region-as-kill (point) (mark)))))
@@ -3079,6 +3071,9 @@ vip-s-string"
                (point-min)
                (if (null ex-addresses) (point-max) (car ex-addresses))))))
 
-(if (file-exists-p "~/.vip") (load "~/.vip"))
+(if (file-exists-p vip-startup-file) (load vip-startup-file))
+
+(provide 'vip)
 
+;;; arch-tag: bff623ef-48f7-41d4-9aa3-2e840c9ab415
 ;;; vip.el ends here