代码:
;;这几个来自Textmate
;;默认COPY,CUT整行 (defadvice kill-ring-save (before slickcopy activate compile) "When called interactively with no active region, copy a single line instead." (interactive (if mark-active (list (region-beginning) (region-end)) (list (line-beginning-position) (line-beginning-position 2))))) (defadvice kill-region (before slickcut activate compile) "When called interactively with no active region, kill a single line instead." (interactive (if mark-active (list (region-beginning) (region-end)) (list (line-beginning-position) (line-beginning-position 2)))))
;;删除语法快 (global-set-key [(control w)] 'kill-syntax-backward) (global-set-key [(control d)] 'kill-syntax-forward)
(defun kill-syntax-forward () "Kill characters with syntax at point." (interactive) (kill-region (point) (progn (skip-syntax-forward (string (char-syntax (char-after)))) (point))))
(defun kill-syntax-backward () "Kill characters with syntax at point." (interactive) (kill-region (point) (progn (skip-syntax-backward (string (char-syntax (char-before)))) (point))))
;;可以给选中的region加个外包比如"region" (require 'wrap-region)
;;移动整行 (global-set-key [(meta up)] 'move-line-up) (global-set-key [(meta down)] 'move-line-down)
(defun move-line (&optional n) "Move current line N (1) lines up/down leaving point in place." (interactive "p") (when (null n) (setq n 1)) (let ((col (current-column))) (beginning-of-line) (next-line 1) (transpose-lines n) (previous-line 1) (forward-char col))) (defun move-line-up (n) "Moves current line N (1) lines up leaving point in place." (interactive "p") (move-line (if (null n) -1 (- n))))
(defun move-line-down (n) "Moves current line N (1) lines down leaving point in place." (interactive "p") (move-line (if (null n) 1 n)))
;;这几个来自VIM
;;括号匹配,当 % 在括号上按下时,那么匹配括号,否则输入一个 %。 (global-set-key "%" 'match-paren) (defun match-paren (arg) "Go to the matching paren if on a paren; otherwise insert %." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1)))))
;;go-to-char,C-z a (defun wy-go-to-char (n char) "Move forward to Nth occurence of CHAR. Typing `wy-go-to-char-key' again will move forwad to the next Nth occurence of CHAR." (interactive "p\ncGo to char: ") (search-forward (string char) nil nil n) (while (char-equal (read-char) char) (search-forward (string char) nil nil n)) (setq unread-command-events (list last-input-event)))
(define-key global-map (kbd "C-z a") 'wy-go-to-char)
;; 先用 highlight-regexp,再用 hi-lock-next 移动到 ;; 下一个匹配。比较类似 vim 的 n 和 N。 (global-set-key (kbd "C-z h") 'highlight-regexp) (global-set-key (kbd "C-z n") 'hi-lock-next) (global-set-key (kbd "C-z p") 'hi-lock-previous) ;; view-mode 是用于浏览文件的一个很好用的 mode。可以加一些 vim normal (global-set-key (kbd "C-z vi") 'view-mode) ;; 为 view-mode 加入 vim 的按键。 (setq view-mode-hook (lambda () (define-key view-mode-map "h" 'backward-char) (define-key view-mode-map "l" 'forward-char) (define-key view-mode-map "j" 'next-line) (define-key view-mode-map "k" 'previous-line))) ;; 自动导入hi-lock+ 插件。autoload 的用处在于它不是启动时导入这 ;; 个 elisp,而是在你调用这个命令时才导入。这样可以加快启动速度。你也可 ;; 以类似的加入一些要自动导入的命令。 (dolist (cm '(hi-lock-previous hi-lock-next toggle-tabs-font-lock toggle-trailing-whitespace-font-lock toggle-whitespace-font-lock)) (autoload cm "hi-lock+" "Hi-lock assist command" t))
;;ann77 的一个 elisp,用于跳转到前一个大幅度跳转的位置。类似于 vim 的 C-o 和 C-i。 (require 'recent-jump nil t) (when (featurep 'recent-jump) (global-set-key (kbd "M-o") 'recent-jump-jump-backward) (global-set-key (kbd "M-i") 'recent-jump-jump-forward))
;;类似 vim 的字典 (setq ywb-dict-file "~/.emacs.d/elisp/my.dict") (defun ywb-read-dict-file () "Read dictionary file" (interactive) (if (file-exists-p ywb-dict-file) (save-excursion (let ((buffer (find-file-noselect ywb-dict-file)) (done nil) mode beg end) (set-buffer buffer) (goto-char (point-min)) (re-search-forward "^\\*\\s-*\\(.*-mode\\)" nil t) (setq mode (buffer-substring (match-beginning 1) (match-end 1))) (setq beg (1+ (match-end 0))) (while (progn (if (re-search-forward "^\\*\\s-*\\(.*-mode\\)" nil t) (setq end (match-beginning 0)) (setq end (point-max)) (setq done t)) ;; (message "mode: %s, beg: %d, end: %d" mode beg end) (with-current-buffer (get-buffer-create (format " %s-dict" mode)) (erase-buffer) (setq major-mode (intern mode)) (insert-buffer-substring buffer beg end)) (setq mode (match-string 1)) (setq beg (1+ (match-end 0))) (not done))) (kill-buffer buffer))) (message "file %s is not exits!" ywb-dict-file))) (ywb-read-dict-file)
[此贴被 尤里西斯(amr) 在 04月18日19时51分 编辑过]
|