📄 vip.el
字号:
(setq vip-F-char vip-f-char);; set new vip-F-char (forward-char) (vip-execute-com 'vip-goto-char-forward val com)))))(defun vip-find-char-backward (arg) "Find char ARG on line backward." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getcom arg))) (if (> val 0) ;; this means that the function was called interactively (setq vip-f-char (read-char) vip-f-forward nil vip-f-offset nil) (setq val (- val))) (if com (move-marker vip-com-point (point))) (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil nil) (setq val (- val)) (if com (progn (setq vip-F-char vip-f-char);; set new vip-F-char (vip-execute-com 'vip-find-char-backward val com)))))(defun vip-goto-char-backward (arg) "Go up to char ARG backward on line." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getcom arg))) (if (> val 0) ;; this means that the function was called interactively (setq vip-f-char (read-char) vip-f-forward nil vip-f-offset t) (setq val (- val))) (if com (move-marker vip-com-point (point))) (vip-find-char val (if (> (vip-p-val arg) 0) vip-f-char vip-F-char) nil t) (setq val (- val)) (if com (progn (setq vip-F-char vip-f-char);; set new vip-F-char (vip-execute-com 'vip-goto-char-backward val com)))))(defun vip-repeat-find (arg) "Repeat previous find command." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getcom arg))) (if com (move-marker vip-com-point (point))) (vip-find-char val vip-f-char vip-f-forward vip-f-offset) (if com (progn (if vip-f-forward (forward-char)) (vip-execute-com 'vip-repeat-find val com)))))(defun vip-repeat-find-opposite (arg) "Repeat previous find command in the opposite direction." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getcom arg))) (if com (move-marker vip-com-point (point))) (vip-find-char val vip-f-char (not vip-f-forward) vip-f-offset) (if com (progn (if vip-f-forward (forward-char)) (vip-execute-com 'vip-repeat-find-opposite val com)))));; window scrolling etc.(defun vip-other-window (arg) "Switch to other window." (interactive "p") (other-window arg) (or (not (eq vip-current-mode 'emacs-mode)) (string= (buffer-name (current-buffer)) " *Minibuf-1*") (vip-change-mode-to-vi)))(defun vip-window-top (arg) "Go to home window line." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getCom arg))) (if com (move-marker vip-com-point (point))) (move-to-window-line (1- val)) (if com (vip-execute-com 'vip-window-top val com))))(defun vip-window-middle (arg) "Go to middle window line." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getCom arg))) (if com (move-marker vip-com-point (point))) (move-to-window-line (+ (/ (1- (window-height)) 2) (1- val))) (if com (vip-execute-com 'vip-window-middle val com))))(defun vip-window-bottom (arg) "Go to last window line." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getCom arg))) (if com (move-marker vip-com-point (point))) (move-to-window-line (- val)) (if com (vip-execute-com 'vip-window-bottom val com))))(defun vip-line-to-top (arg) "Put current line on the home line." (interactive "p") (recenter (1- arg)))(defun vip-line-to-middle (arg) "Put current line on the middle line." (interactive "p") (recenter (+ (1- arg) (/ (1- (window-height)) 2))))(defun vip-line-to-bottom (arg) "Put current line on the last line." (interactive "p") (recenter (- (window-height) (1+ arg))));; paren match(defun vip-paren-match (arg) "Go to the matching parenthesis." (interactive "P") (let ((com (vip-getcom arg))) (if (numberp arg) (if (or (> arg 99) (< arg 1)) (error "Prefix must be between 1 and 99.") (goto-char (if (> (point-max) 80000) (* (/ (point-max) 100) arg) (/ (* (point-max) arg) 100))) (back-to-indentation)) (cond ((looking-at "[\(\[{]") (if com (move-marker vip-com-point (point))) (forward-sexp 1) (if com (vip-execute-com 'vip-paren-match nil com) (backward-char))) ((looking-at "[])}]") (forward-char) (if com (move-marker vip-com-point (point))) (backward-sexp 1) (if com (vip-execute-com 'vip-paren-match nil com))) (t (error ""))))));; sentence and paragraph(defun vip-forward-sentence (arg) "Forward sentence." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getcom arg))) (if com (move-marker vip-com-point (point))) (forward-sentence val) (if com (vip-execute-com 'vip-forward-sentence nil com))))(defun vip-backward-sentence (arg) "Backward sentence." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getcom arg))) (if com (move-marker vip-com-point (point))) (backward-sentence val) (if com (vip-execute-com 'vip-backward-sentence nil com))))(defun vip-forward-paragraph (arg) "Forward paragraph." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getCom arg))) (if com (move-marker vip-com-point (point))) (forward-paragraph val) (if com (vip-execute-com 'vip-forward-paragraph nil com))))(defun vip-backward-paragraph (arg) "Backward paragraph." (interactive "P") (let ((val (vip-p-val arg)) (com (vip-getCom arg))) (if com (move-marker vip-com-point (point))) (backward-paragraph val) (if com (vip-execute-com 'vip-backward-paragraph nil com))));; scrolling(defun vip-scroll (arg) "Scroll to next screen." (interactive "p") (if (> arg 0) (while (> arg 0) (scroll-up) (setq arg (1- arg))) (while (> 0 arg) (scroll-down) (setq arg (1+ arg)))))(defun vip-scroll-back (arg) "Scroll to previous screen." (interactive "p") (vip-scroll (- arg)))(defun vip-scroll-down (arg) "Scroll up half screen." (interactive "P") (if (null arg) (scroll-down (/ (window-height) 2)) (scroll-down arg)))(defun vip-scroll-down-one (arg) "Scroll up one line." (interactive "p") (scroll-down arg))(defun vip-scroll-up (arg) "Scroll down half screen." (interactive "P") (if (null arg) (scroll-up (/ (window-height) 2)) (scroll-up arg)))(defun vip-scroll-up-one (arg) "Scroll down one line." (interactive "p") (scroll-up arg));; splitting window(defun vip-buffer-in-two-windows () "Show current buffer in two windows." (interactive) (delete-other-windows) (split-window-vertically nil));; searching(defun vip-search-forward (arg) "Search a string forward. ARG is used to find the ARG's occurenceof the string. Default is vanilla search. Search mode can be toggled bygiving null search string." (interactive "P") (let ((val (vip-P-val arg)) (com (vip-getcom arg))) (setq vip-s-forward t vip-s-string (vip-read-string (if vip-re-search "RE-/" "/"))) (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")))) (vip-search vip-s-string t val) (if com (progn (move-marker vip-com-point (mark)) (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 occurenceof the string. Default is vanilla search. Search mode can be toggled bygiving null search string." (interactive "P") (let ((val (vip-P-val arg)) (com (vip-getcom arg))) (setq vip-s-forward nil vip-s-string (vip-read-string (if vip-re-search "RE-?" "?"))) (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")))) (vip-search vip-s-string nil val) (if com (progn (move-marker vip-com-point (mark)) (vip-execute-com 'vip-search-next val com))))))(defun vip-search (string forward arg &optional no-offset init-point) "(STRING FORWARD COUNT &optional NO-OFFSET) Search COUNT's occurrence ofSTRING. Search will be forward if FORWARD, otherwise backward." (let ((val (vip-p-val arg)) (com (vip-getcom arg)) (null-arg (null (vip-P-val arg))) (offset (not no-offset)) (case-fold-search vip-case-fold-search) (start-point (or init-point (point)))) (if forward (condition-case conditions (progn (if (and offset (not (eobp))) (forward-char)) (if vip-re-search (progn (re-search-forward string nil nil val) (re-search-backward string)) (search-forward string nil nil val) (search-backward string)) (push-mark start-point)) (search-failed (if (and null-arg vip-search-wrap-around) (progn (goto-char (point-min)) (vip-search string forward (cons 1 com) t start-point)) (goto-char start-point) (signal 'search-failed (cdr conditions))))) (condition-case conditions (progn (if vip-re-search (re-search-backward string nil nil val) (search-backward string nil nil val)) (push-mark start-point)) (search-failed (if (and null-arg vip-search-wrap-around) (progn (goto-char (point-max)) (vip-search string forward (cons 1 com) t start-point)) (goto-char start-point) (signal 'search-failed (cdr conditions))))))))(defun vip-search-next (arg) "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.")) (vip-search vip-s-string vip-s-forward arg) (if com (vip-execute-com 'vip-search-next val com))))(defun vip-search-Next (arg) "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.")) (vip-search vip-s-string (not vip-s-forward) arg) (if com (vip-execute-com 'vip-search-Next val com))));; visiting and killing files, buffers(defun vip-switch-to-buffer () "Switch to buffer in the current window." (interactive) (let (buffer) (setq buffer (read-buffer (format "switch to buffer \(%s\): " (buffer-name (other-buffer (current-buffer)))))) (switch-to-buffer buffer) (vip-change-mode-to-vi)))(defun vip-switch-to-buffer-other-window () "Switch to buffer in another window." (interactive) (let (buffer) (setq buffer (read-buffer (format "Switch to buffer \(%s\): " (buffer-name (other-buffer (current-buffer)))))) (switch-to-buffer-other-window buffer) (vip-change-mode-to-vi)))(defun vip-kill-buffer () "Kill a buffer." (interactive) (let (buffer buffer-name) (setq buffer-name (read-buffer (format "Kill buffer \(%s\): " (buffer-name (current-buffer))))) (setq buffer (if (null buffer-name) (current-buffer) (get-buffer 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."))))(defun vip-find-file () "Visit file in the current window." (interactive) (let (file) (setq file (read-file-name "visit file: ")) (switch-to-buffer (find-file-noselect file)) (vip-change-mode-to-vi)))(defun vip-find-file-other-window () "Visit file in another window." (interactive) (let (file) (setq file (read-file-name "Visit file: ")) (switch-to-buffer-other-window (find-file-noselect file)) (vip-change-mode-to-vi)))(defun vip-info-on-file () "Give information of the file associated to the current buffer." (interactive) (message "\"%s\" line %d of %d" (if (buffer-file-name) (buffer-file-name) "") (1+ (count-lines (point-min) (point))) (1+ (count-lines (point-min) (point-max)))));; yank and pop(defun vip-yank (text) "yank TEXT silently." (save-excursion (vip-push-mark-silent (point)) (insert text) (exchange-point-and-mark)) (skip-chars-forward " \t"))(defun vip-put-back (arg) "Put back after point/below line." (interactive "P") (let ((val (vip-p-val arg))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -