⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vi.el

📁 早期freebsd实现
💻 EL
📖 第 1 页 / 共 4 页
字号:
;  (make-local-variable 'vi-add-to-mode-line);  (setq vi-add-to-mode-line vi-add-to-mode-line-1);  (or (memq vi-add-to-mode-line minor-mode-alist);      (setq minor-mode-alist (cons vi-add-to-mode-line minor-mode-alist)))  (make-local-variable 'vi-scroll-amount)  (setq vi-scroll-amount (/ (window-height) 2))  (make-local-variable 'vi-shift-width)  (setq vi-shift-width 4)  (make-local-variable 'vi-ins-point)  (make-local-variable 'vi-ins-length)  (make-local-variable 'vi-ins-repetition)  (make-local-variable 'vi-ins-overwrt-p)  (make-local-variable 'vi-ins-prefix-code)  (make-local-variable 'vi-last-change-command)  (make-local-variable 'vi-last-shell-command)  (make-local-variable 'vi-last-find-char)  (make-local-variable 'vi-mark-alist)  (make-local-variable 'vi-insert-state)  (make-local-variable 'vi-mode-old-local-map)  (make-local-variable 'vi-mode-old-mode-name)  (make-local-variable 'vi-mode-old-major-mode)  (make-local-variable 'vi-mode-old-case-fold)  (run-hooks 'vi-mode-hook))      (defun vi-mode ()  "Major mode that acts like the `vi' editor.The purpose of this mode is to provide you the combined power of vi (namely,the \"cross product\" effect of commands and repeat last changes) and Emacs.This command redefines nearly all keys to look like vi commands.It records the previous major mode, and any vi command for input\(`i', `a', `s', etc.) switches back to that mode.Thus, ordinary Emacs (in whatever major mode you had been using)is \"input\" mode as far as vi is concerned.To get back into vi from \"input\" mode, you must issue this command again.Therefore, it is recommended that you assign it to a key.Major differences between this mode and real vi :* Limitations and unsupported features  - Search patterns with line offset (e.g. /pat/+3 or /pat/z.) are    not supported.  - Ex commands are not implemented; try ':' to get some hints.  - No line undo (i.e. the 'U' command), but multi-undo is a standard feature.* Modifications  - The stopping positions for some point motion commands (word boundary,    pattern search) are slightly different from standard 'vi'.    Also, no automatic wrap around at end of buffer for pattern searching.  - Since changes are done in two steps (deletion then insertion), you need    to undo twice to completely undo a change command.  But this is not needed    for undoing a repeated change command.  - No need to set/unset 'magic', to search for a string with regular expr    in it just put a prefix arg for the search commands.  Replace cmds too.  - ^R is bound to incremental backward search, so use ^L to redraw screen.* Extensions  - Some standard (or modified) Emacs commands were integrated, such as    incremental search, query replace, transpose objects, and keyboard macros.  - In command state, ^X links to the 'ctl-x-map', and ESC can be linked to    esc-map or set undefined.  These can give you the full power of Emacs.  - See vi-com-map for those keys that are extensions to standard vi, e.g.    `vi-name-last-change-or-macro', `vi-verify-spelling', `vi-locate-def',    `vi-mark-region', and 'vi-quote-words'.  Some of them are quite handy.  - Use \\[vi-switch-mode] to switch among different modes quickly.  Syntax table and abbrevs while in vi mode remain as they were in Emacs."   (interactive)   (if (null vi-mode-old-major-mode)	; very first call for current buffer       (vi-mode-setup))   (if (eq major-mode 'vi-mode)       (message "Already in vi-mode." (ding))     (setq vi-mode-old-local-map (current-local-map))     (setq vi-mode-old-mode-name mode-name)     (setq vi-mode-old-major-mode major-mode)     (setq vi-mode-old-case-fold case-fold-search) ; this is needed !!     (setq case-fold-search nil)	; exact case match in searching     (use-local-map vi-com-map)     (setq major-mode 'vi-mode)     (setq mode-name "VI")     (set-buffer-modified-p (buffer-modified-p))  ; force mode line update     (if vi-insert-state	        ; this is a return from insertion         (vi-end-of-insert-state))))(defun vi-ding()  "Ding !"  (interactive)  (ding))(defun vi-save-all-and-exit ()  "Save all modified buffers without asking, then exits emacs."  (interactive)  (save-some-buffers t)  (kill-emacs));; to be used by "ex" commands(defvar vi-replaced-string nil)(defvar vi-replacing-string nil)(defun vi-ex-cmd ()  "Ex commands are not implemented in Evi mode.  For some commonly used excommands, you can use the following alternatives for similar effect :w            C-x C-s (save-buffer)wq           C-x C-c (save-buffers-kill-emacs)w fname      C-x C-w (write-file)e fname      C-x C-f (find-file)r fname      C-x i   (insert-file)s/old/new    use q (vi-replace) to do unconditional replace             use C-q (vi-query-replace) to do query replaceset sw=n     M-x set-variable vi-shift-width n "  (interactive);; (let ((cmd (read-string ":")) (lines 1));;  (cond ((string-match "s"))))  (with-output-to-temp-buffer "*Help*"    (princ (documentation 'vi-ex-cmd))))(defun vi-undefined ()  (interactive)  (message "Command key \"%s\" is undefined in Evi."	   (single-key-description last-command-char))  (ding))(defun vi-unimplemented ()  (interactive)  (message "Command key \"%s\" is not implemented in Evi."	   (single-key-description last-command-char))  (ding));;;;;(defun vi-goto-insert-state (repetition &optional prefix-code do-it-now-p)  "Go into insert state, the text entered will be repeated if REPETITION > 1.If PREFIX-CODE is given, do it before insertion begins if DO-IT-NOW-P is T.In any case, the prefix-code will be done before each 'redo-insert'.This function expects 'overwrite-mode' being set properly beforehand."  (if do-it-now-p (apply (car prefix-code) (cdr prefix-code)))  (setq vi-ins-point (point))  (setq vi-ins-repetition repetition)  (setq vi-ins-prefix-code prefix-code)  (setq mode-name vi-mode-old-mode-name)  (setq case-fold-search vi-mode-old-case-fold)  (use-local-map vi-mode-old-local-map)  (setq major-mode vi-mode-old-major-mode)  (set-buffer-modified-p (buffer-modified-p))  ; force mode line update  (setq vi-insert-state t))(defun vi-end-of-insert-state ()  "Terminate insertion and set up last change command."  (if (or (< (point) vi-ins-point)    ;Check if there is any effective change	  (and (= (point) vi-ins-point) (null vi-ins-prefix-code))	  (<= vi-ins-repetition 0))      (vi-goto-command-state t)    (if (> vi-ins-repetition 1)	(progn 	  (let ((str (buffer-substring vi-ins-point (point))))	    (while (> vi-ins-repetition 1)	      (insert str)	      (setq vi-ins-repetition (1- vi-ins-repetition))))))    (vi-set-last-change-command 'vi-first-redo-insertion vi-ins-point (point)			     overwrite-mode vi-ins-prefix-code)    (vi-goto-command-state t)))(defun vi-first-redo-insertion (begin end &optional overwrite-p prefix-code)  "Redo last insertion the first time.  Extract the string and save it forfuture redoes.  Do prefix-code if it's given, use overwrite mode if asked."  (let ((str (buffer-substring begin end)))    (if prefix-code (apply (car prefix-code) (cdr prefix-code)))    (if overwrite-p (delete-region (point) (+ (point) (length str))))    (insert str)    (vi-set-last-change-command 'vi-more-redo-insertion str overwrite-p prefix-code)))(defun vi-more-redo-insertion (str &optional overwrite-p prefix-code)  "Redo more insertion : copy string from STR to point, use overwrite modeif overwrite-p is T; apply prefix-code first if it's non-nil."  (if prefix-code (apply (car prefix-code) (cdr prefix-code)))  (if overwrite-p (delete-region (point) (+ (point) (length str))))  (insert str))(defun vi-goto-command-state (&optional from-insert-state-p)  "Go to vi-mode command state.  If optional arg exists, means return frominsert state."  (use-local-map vi-com-map)  (setq vi-insert-state nil)  (if from-insert-state-p      (if overwrite-mode	  (overwrite-mode 0);	(set-minor-mode 'ins "Insert" nil)	)))(defun vi-kill-line (arg)   "kill specified number of lines (=d$), text saved in the kill ring."   (interactive "*P")   (kill-line arg)   (vi-set-last-change-command 'kill-line arg))(defun vi-kill-region ()  (interactive)  (kill-region)  (vi-set-last-change-command 'kill-region))  (defun vi-append-at-end-of-line (arg)   "go to end of line and then go into vi insert state."   (interactive "*p")   (vi-goto-insert-state arg '(end-of-line) t))(defun vi-change-rest-of-line (arg)  "Change the rest of (ARG) lines (= c$ in vi)."  (interactive "*P")  (vi-goto-insert-state 1 (list 'kill-line arg) t))(defun vi-insert-before-first-nonwhite (arg)  "(= ^i in vi)"  (interactive "*p")  (vi-goto-insert-state arg '(back-to-indentation) t))(defun vi-open-above (arg)  "open new line(s) above current line and enter insert state."  (interactive "*p")  (vi-goto-insert-state 1			(list (function (lambda (x)					  (or (beginning-of-line)					      (open-line x)))) arg)			t))(defun vi-open-below (arg)  "open new line(s) and go into insert mode on the last line."  (interactive "*p")  (vi-goto-insert-state 1			(list (function (lambda (x)					  (or (end-of-line)					    (open-line x)					    (forward-line x)))) arg)			t))(defun vi-insert-after (arg)   "start vi insert state after cursor."   (interactive "*p")   (vi-goto-insert-state arg			 (list (function (lambda ()					   (if (not (eolp)) (forward-char)))))			 t))(defun vi-insert-before (arg)  "enter insert state before the cursor."  (interactive "*p")  (vi-goto-insert-state arg))(defun vi-goto-line (arg)   "Go to ARGth line."   (interactive "P")   (if (null (vi-raw-numeric-prefix arg))       (end-of-buffer)     (goto-line (vi-prefix-numeric-value arg))))(defun vi-beginning-of-buffer ()  "Move point to the beginning of current buffer."  (interactive)  (goto-char (point-min)));;;;; not used now;;(defvar regexp-search t		; string;;  "*T if search string can contain regular expressions. (= set magic in vi)");;;;;(defun vi-isearch-forward (arg)  "Incremental search forward.  Use regexp version if ARG is non-nil."   (interactive "P")  (let ((scmd (if arg 'isearch-forward-regexp 'isearch-forward))	(opoint (point)))    (call-interactively scmd)    (if (= opoint (point))	nil      (setq vi-search-last-command (if arg 're-search-forward 'search-forward)))))(defun vi-isearch-backward (arg)  "Incremental search backward.  Use regexp version if ARG is non-nil."  (interactive "P")  (let ((scmd (if arg 'isearch-backward-regexp 'isearch-backward))	(opoint (point)))    (call-interactively scmd)    (if (= opoint (point))	nil      (setq vi-search-last-command (if arg 're-search-backward 'search-backward)))))(defun vi-search-forward (arg string)   "Nonincremental search forward. Use regexp version if ARG is non-nil."   (interactive (if current-prefix-arg		    (list t (read-string "regexp/" nil))		  (list nil (read-string "/" nil))))   (setq vi-search-last-command (if arg 're-search-forward 'search-forward))   (if (> (length string) 0) (setq search-last-string string))    (funcall vi-search-last-command search-last-string nil nil 1))(defun vi-search-backward (arg string)   "Nonincremental search backward.  Use regexp version if ARG is non-nil."   (interactive (if current-prefix-arg		    (list t (read-string "regexp?" nil))		  (list nil (read-string "?" nil))))   (setq vi-search-last-command (if arg 're-search-backward 'search-backward))   (if (> (length string) 0) (setq search-last-string string))    (funcall vi-search-last-command search-last-string nil nil 1))(defun vi-repeat-last-search (arg &optional search-command search-string)   "Repeat last search command.  If optional search-command/string are given,use those instead of the ones saved."   (interactive "p")   (if (null search-command) (setq search-command vi-search-last-command))   (if (null search-string) (setq search-string search-last-string))   (if (null search-command)       (message "No last search command to repeat." (ding))     (funcall search-command search-string nil nil arg)))(defun vi-reverse-last-search (arg &optional search-command search-string)  "Redo last search command in reverse direction. If the optional search argsare given, use those instead of the ones saved."  (interactive "p")  (if (null search-command) (setq search-command vi-search-last-command))  (if (null search-string) (setq search-string search-last-string))  (if (null search-command)      (message "No last search command to repeat." (ding))    (funcall (cond ((eq search-command 're-search-forward) 're-search-backward)		   ((eq search-command 're-search-backward) 're-search-forward)		   ((eq search-command 'search-forward) 'search-backward)		   ((eq search-command 'search-backward) 'search-forward))	     search-string nil nil arg)))       (defun vi-join-lines (arg)   "join ARG lines from current line (default 2), cleaning up white space."   (interactive "P")   (if (null (vi-raw-numeric-prefix arg))       (delete-indentation t)     (setq count (vi-prefix-numeric-value arg))     (while (>= count 2)       (delete-indentation t)       (setq count (1- count))))   (vi-set-last-change-command 'vi-join-lines arg))(defun vi-backward-kill-line ()   "kill the current line.  Only works in insert state."   (interactive)   (if (not vi-insert-state)       nil     (beginning-of-line 1)     (kill-line nil)))(defun vi-abort-ins ()  "abort insert state, kill inserted text and go back to command state."  (interactive)  (if (not vi-insert-state)      nil    (if (> (point) vi-ins-point)	   (kill-region vi-ins-point (point)))    (vi-goto-command-state t)))(defun vi-backward-windowfull (count)  "Backward COUNT windowfulls. Default is one."  (interactive "p"); (set-mark-command nil)  (while (> count 0)    (scroll-down nil)    (setq count (1- count))))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -