30 |
; (vi-mode)))))) |
; (vi-mode)))))) |
31 |
; 3) In your .emacs file you can define the command "vi-mode" to be "autoload" |
; 3) In your .emacs file you can define the command "vi-mode" to be "autoload" |
32 |
; or you can execute the "load" command to load "vi" directly. |
; or you can execute the "load" command to load "vi" directly. |
33 |
; 4) Read the comments for command "vi-mode" before you start using it. |
; 4) Read the comments for command "vi-mode" before you start using it. |
34 |
; |
; |
35 |
; COULD DO |
; COULD DO |
36 |
; 1). A general 'define-operator' function to replace current hack |
; 1). A general 'define-operator' function to replace current hack |
153 |
(define-key vi-com-map "\C-\\" 'vi-unimplemented) |
(define-key vi-com-map "\C-\\" 'vi-unimplemented) |
154 |
(define-key vi-com-map "\C-]" 'find-tag) |
(define-key vi-com-map "\C-]" 'find-tag) |
155 |
(define-key vi-com-map "\C-^" 'vi-locate-def) ; extension |
(define-key vi-com-map "\C-^" 'vi-locate-def) ; extension |
156 |
(define-key vi-com-map "\C-_" 'vi-undefined) |
(define-key vi-com-map "\C-_" 'vi-undefined) |
157 |
|
|
158 |
(define-key vi-com-map " " 'forward-char) |
(define-key vi-com-map " " 'forward-char) |
159 |
(define-key vi-com-map "!" 'vi-operator) |
(define-key vi-com-map "!" 'vi-operator) |
201 |
(define-key vi-com-map "H" 'vi-home-window-line) |
(define-key vi-com-map "H" 'vi-home-window-line) |
202 |
(define-key vi-com-map "I" 'vi-insert-before-first-nonwhite) |
(define-key vi-com-map "I" 'vi-insert-before-first-nonwhite) |
203 |
(define-key vi-com-map "J" 'vi-join-lines) |
(define-key vi-com-map "J" 'vi-join-lines) |
204 |
(define-key vi-com-map "K" 'vi-undefined) |
(define-key vi-com-map "K" 'vi-undefined) |
205 |
(define-key vi-com-map "L" 'vi-last-window-line) |
(define-key vi-com-map "L" 'vi-last-window-line) |
206 |
(define-key vi-com-map "M" 'vi-middle-window-line) |
(define-key vi-com-map "M" 'vi-middle-window-line) |
207 |
(define-key vi-com-map "N" 'vi-reverse-last-search) |
(define-key vi-com-map "N" 'vi-reverse-last-search) |
212 |
(define-key vi-com-map "S" 'vi-substitute-lines) |
(define-key vi-com-map "S" 'vi-substitute-lines) |
213 |
(define-key vi-com-map "T" 'vi-backward-upto-char) |
(define-key vi-com-map "T" 'vi-backward-upto-char) |
214 |
(define-key vi-com-map "U" 'vi-unimplemented) |
(define-key vi-com-map "U" 'vi-unimplemented) |
215 |
(define-key vi-com-map "V" 'vi-undefined) |
(define-key vi-com-map "V" 'vi-undefined) |
216 |
(define-key vi-com-map "W" 'vi-forward-blank-delimited-word) |
(define-key vi-com-map "W" 'vi-forward-blank-delimited-word) |
217 |
(define-key vi-com-map "X" 'call-last-kbd-macro) ; modification/extension |
(define-key vi-com-map "X" 'call-last-kbd-macro) ; modification/extension |
218 |
(define-key vi-com-map "Y" 'vi-yank-line) |
(define-key vi-com-map "Y" 'vi-yank-line) |
247 |
(define-key vi-com-map "s" 'vi-substitute-chars) |
(define-key vi-com-map "s" 'vi-substitute-chars) |
248 |
(define-key vi-com-map "t" 'vi-forward-upto-char) |
(define-key vi-com-map "t" 'vi-forward-upto-char) |
249 |
(define-key vi-com-map "u" 'undo) |
(define-key vi-com-map "u" 'undo) |
250 |
(define-key vi-com-map "v" 'vi-verify-spelling) |
(define-key vi-com-map "v" 'vi-verify-spelling) |
251 |
(define-key vi-com-map "w" 'vi-forward-word) |
(define-key vi-com-map "w" 'vi-forward-word) |
252 |
(define-key vi-com-map "x" 'vi-kill-char) |
(define-key vi-com-map "x" 'vi-kill-char) |
253 |
(define-key vi-com-map "y" 'vi-operator) |
(define-key vi-com-map "y" 'vi-operator) |
355 |
"Non-nil if it is in insert state.") |
"Non-nil if it is in insert state.") |
356 |
|
|
357 |
; in "loaddefs.el" |
; in "loaddefs.el" |
358 |
;(defvar search-last-string "" |
;(defvar search-last-string "" |
359 |
; "Last string search for by a search command.") |
; "Last string search for by a search command.") |
360 |
|
|
361 |
(defvar vi-search-last-command nil ; (re-)search-forward(backward) |
(defvar vi-search-last-command nil ; (re-)search-forward(backward) |
366 |
|
|
367 |
(defvar vi-mode-old-mode-name nil |
(defvar vi-mode-old-mode-name nil |
368 |
"Save the mode-name before entering vi-mode.") |
"Save the mode-name before entering vi-mode.") |
369 |
|
|
370 |
(defvar vi-mode-old-major-mode nil |
(defvar vi-mode-old-major-mode nil |
371 |
"Save the major-mode before entering vi-mode.") |
"Save the major-mode before entering vi-mode.") |
372 |
|
|
373 |
(defvar vi-mode-old-case-fold nil) |
(defvar vi-mode-old-case-fold nil) |
374 |
|
|
375 |
;(defconst vi-add-to-mode-line-1 |
;(defconst vi-add-to-mode-line-1 |
376 |
; '(overwrite-mode nil " Insert")) |
; '(overwrite-mode nil " Insert")) |
377 |
|
|
404 |
(make-local-variable 'vi-mode-old-major-mode) |
(make-local-variable 'vi-mode-old-major-mode) |
405 |
(make-local-variable 'vi-mode-old-case-fold) |
(make-local-variable 'vi-mode-old-case-fold) |
406 |
(run-hooks 'vi-mode-hook)) |
(run-hooks 'vi-mode-hook)) |
407 |
|
|
408 |
;;;###autoload |
;;;###autoload |
409 |
(defun vi-mode () |
(defun vi-mode () |
410 |
"Major mode that acts like the `vi' editor. |
"Major mode that acts like the `vi' editor. |
448 |
`vi-name-last-change-or-macro', `vi-verify-spelling', `vi-locate-def', |
`vi-name-last-change-or-macro', `vi-verify-spelling', `vi-locate-def', |
449 |
`vi-mark-region', and 'vi-quote-words'. Some of them are quite handy. |
`vi-mark-region', and 'vi-quote-words'. Some of them are quite handy. |
450 |
- Use \\[vi-switch-mode] to switch among different modes quickly. |
- Use \\[vi-switch-mode] to switch among different modes quickly. |
451 |
|
|
452 |
Syntax table and abbrevs while in vi mode remain as they were in Emacs." |
Syntax table and abbrevs while in vi mode remain as they were in Emacs." |
453 |
(interactive) |
(interactive) |
454 |
(if (null vi-mode-old-major-mode) ; very first call for current buffer |
(if (null vi-mode-old-major-mode) ; very first call for current buffer |
539 |
(<= vi-ins-repetition 0)) |
(<= vi-ins-repetition 0)) |
540 |
(vi-goto-command-state t) |
(vi-goto-command-state t) |
541 |
(if (> vi-ins-repetition 1) |
(if (> vi-ins-repetition 1) |
542 |
(progn |
(progn |
543 |
(let ((str (buffer-substring vi-ins-point (point)))) |
(let ((str (buffer-substring vi-ins-point (point)))) |
544 |
(while (> vi-ins-repetition 1) |
(while (> vi-ins-repetition 1) |
545 |
(insert str) |
(insert str) |
585 |
(interactive "*r") |
(interactive "*r") |
586 |
(kill-region start end) |
(kill-region start end) |
587 |
(vi-set-last-change-command 'kill-region)) |
(vi-set-last-change-command 'kill-region)) |
588 |
|
|
589 |
(defun vi-append-at-end-of-line (arg) |
(defun vi-append-at-end-of-line (arg) |
590 |
"go to end of line and then go into vi insert state." |
"go to end of line and then go into vi insert state." |
591 |
(interactive "*p") |
(interactive "*p") |
651 |
;;;;; |
;;;;; |
652 |
|
|
653 |
(defun vi-isearch-forward (arg) |
(defun vi-isearch-forward (arg) |
654 |
"Incremental search forward. Use regexp version if ARG is non-nil." |
"Incremental search forward. Use regexp version if ARG is non-nil." |
655 |
(interactive "P") |
(interactive "P") |
656 |
(let ((scmd (if arg 'isearch-forward-regexp 'isearch-forward)) |
(let ((scmd (if arg 'isearch-forward-regexp 'isearch-forward)) |
657 |
(opoint (point))) |
(opoint (point))) |
724 |
((eq search-command 'search-forward) 'search-backward) |
((eq search-command 'search-forward) 'search-backward) |
725 |
((eq search-command 'search-backward) 'search-forward)) |
((eq search-command 'search-backward) 'search-forward)) |
726 |
search-string nil nil arg))) |
search-string nil nil arg))) |
727 |
|
|
728 |
(defun vi-join-lines (arg) |
(defun vi-join-lines (arg) |
729 |
"join ARG lines from current line (default 2), cleaning up white space." |
"join ARG lines from current line (default 2), cleaning up white space." |
730 |
(interactive "P") |
(interactive "P") |
842 |
(set-mark-command nil) |
(set-mark-command nil) |
843 |
(goto-char mark) |
(goto-char mark) |
844 |
(if line-flag (back-to-indentation))))))) |
(if line-flag (back-to-indentation))))))) |
845 |
|
|
846 |
(defun vi-goto-line-mark (char) |
(defun vi-goto-line-mark (char) |
847 |
"Go to the line (at first non-white) marked by next char." |
"Go to the line (at first non-white) marked by next char." |
848 |
(interactive "c") |
(interactive "c") |
1062 |
((eq moving-unit 'line) |
((eq moving-unit 'line) |
1063 |
(goto-char begin) (beginning-of-line) (setq begin (point)) |
(goto-char begin) (beginning-of-line) (setq begin (point)) |
1064 |
(goto-char end) (next-line 1) (beginning-of-line) (setq end (point)))) |
(goto-char end) (next-line 1) (beginning-of-line) (setq end (point)))) |
1065 |
(if (> end (point-max)) (setq end (point-max))) ; force in buffer region |
(if (> end (point-max)) (setq end (point-max))) ; force in buffer region |
1066 |
(cons begin end))))) |
(cons begin end))))) |
1067 |
|
|
1068 |
(defun vi-delete-op (motion-command arg) |
(defun vi-delete-op (motion-command arg) |
1106 |
(= (aref string (1- (length string))) ?\n)) |
(= (aref string (1- (length string))) ?\n)) |
1107 |
|
|
1108 |
(defun vi-put-before (arg &optional after-p) |
(defun vi-put-before (arg &optional after-p) |
1109 |
"Put yanked (in vi sense) text back before/above cursor. |
"Put yanked (in vi sense) text back before/above cursor. |
1110 |
If a numeric prefix value (currently it should be >1) is given, put back |
If a numeric prefix value (currently it should be >1) is given, put back |
1111 |
text as lines. If the optional after-p is given, put after/below the cursor." |
text as lines. If the optional after-p is given, put after/below the cursor." |
1112 |
(interactive "P") |
(interactive "P") |
1302 |
(interactive "*P") |
(interactive "*P") |
1303 |
(let ((rcmd (if arg 'replace-regexp 'replace-string))) |
(let ((rcmd (if arg 'replace-regexp 'replace-string))) |
1304 |
(call-interactively rcmd nil))) |
(call-interactively rcmd nil))) |
1305 |
|
|
1306 |
(defun vi-adjust-window (arg position) |
(defun vi-adjust-window (arg position) |
1307 |
"Move current line to the top/center/bottom of the window." |
"Move current line to the top/center/bottom of the window." |
1308 |
(interactive "p\nc") |
(interactive "p\nc") |
1329 |
(ding)))) |
(ding)))) |
1330 |
|
|
1331 |
(defun vi-name-last-change-or-macro (arg char) |
(defun vi-name-last-change-or-macro (arg char) |
1332 |
"Give name to the last change command or just defined kbd macro. |
"Give name to the last change command or just defined kbd macro. |
1333 |
If prefix ARG is given, name last macro, otherwise name last change command. |
If prefix ARG is given, name last macro, otherwise name last change command. |
1334 |
The following CHAR will be the name for the command or macro." |
The following CHAR will be the name for the command or macro." |
1335 |
(interactive "P\nc") |
(interactive "P\nc") |
1343 |
(vi-set-last-change-command 'vi-more-redo-insertion str |
(vi-set-last-change-command 'vi-more-redo-insertion str |
1344 |
overwrite-p prefix-code))) |
overwrite-p prefix-code))) |
1345 |
(fset (intern (char-to-string char)) vi-last-change-command))) |
(fset (intern (char-to-string char)) vi-last-change-command))) |
1346 |
|
|
1347 |
(defun vi-call-named-change-or-macro (count char) |
(defun vi-call-named-change-or-macro (count char) |
1348 |
"Execute COUNT times the keyboard macro definition named by the following CHAR." |
"Execute COUNT times the keyboard macro definition named by the following CHAR." |
1349 |
(interactive "p\nc") |
(interactive "p\nc") |