1 Star 0 Fork 2

zhengchen/emacs

forked from latpaw/emacs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
init-evil.el 6.52 KB
一键复制 编辑 原始数据 按行查看 历史
Chen Bin 提交于 2013-07-17 14:51 . magit-show-commit
(evil-mode 1)
; @see https://github.com/timcharper/evil-surround
(global-surround-mode 1)
;; (evil-set-initial-state 'org-mode 'emacs)
;; Remap org-mode meta keys for convenience
(evil-declare-key 'normal org-mode-map
"gh" 'outline-up-heading
"gl" 'outline-next-visible-heading
"H" 'org-beginning-of-line ; smarter behaviour on headlines etc.
"L" 'org-end-of-line ; smarter behaviour on headlines etc.
"t" 'org-todo ; mark a TODO item as DONE
",c" 'org-cycle
",e" 'org-export-dispatch
",n" 'outline-next-visible-heading
",p" 'outline-previous-visible-heading
",t" 'org-set-tags-command
"$" 'org-end-of-line ; smarter behaviour on headlines etc.
"^" 'org-beginning-of-line ; ditto
"-" 'org-ctrl-c-minus ; change bullet style
"<" 'org-metaleft ; out-dent
">" 'org-metaright ; indent
)
(mapc (lambda (state)
(evil-declare-key state org-mode-map
(kbd "TAB") 'org-cycle
(kbd "M-l") 'org-metaright
(kbd "M-h") 'org-metaleft
(kbd "M-k") 'org-metaup
(kbd "M-j") 'org-metadown
(kbd "M-L") 'org-shiftmetaright
(kbd "M-H") 'org-shiftmetaleft
(kbd "M-K") 'org-shiftmetaup
(kbd "M-J") 'org-shiftmetadown))
'(normal insert))
(loop for (mode . state) in
'(
(Info-mode . emacs)
(term-mode . emacs)
(log-edit-mode . emacs)
(inf-ruby-mode . emacs)
(yari-mode . emacs)
(erc-mode . emacs)
(gud-mode . emacs)
(help-mode . emacs)
(eshell-mode . emacs)
(shell-mode . emacs)
(message-mode . emacs)
(magit-log-edit-mode . emacs)
(fundamental-mode . emacs)
(gtags-select-mode . emacs)
(weibo-timeline-mode . emacs)
(weibo-post-mode . emacs)
(diff-mode . emacs)
(sr-mode . emacs)
(dired-mode . emacs)
(compilation-mode . emacs)
(speedbar-mode . emacs)
(magit-commit-mode . normal)
)
do (evil-set-initial-state mode state))
(define-key evil-ex-completion-map (kbd "M-p") 'previous-complete-history-element)
(define-key evil-ex-completion-map (kbd "M-n") 'next-complete-history-element)
(define-key evil-normal-state-map "Y" (kbd "y$"))
(define-key evil-normal-state-map "+" 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map "-" 'evil-numbers/dec-at-pt)
(define-key evil-normal-state-map "go" 'goto-char)
;; @see http://stackoverflow.com/questions/10569165/how-to-map-jj-to-esc-in-emacs-evil-mode
;; @see http://zuttobenkyou.wordpress.com/2011/02/15/some-thoughts-on-emacs-and-vim/
(define-key evil-insert-state-map "k" #'cofi/maybe-exit)
(evil-define-command cofi/maybe-exit ()
:repeat change
(interactive)
(let ((modified (buffer-modified-p)))
(insert "k")
(let ((evt (read-event (format "Insert %c to exit insert state" ?j)
nil 0.5)))
(cond
((null evt) (message ""))
((and (integerp evt) (char-equal evt ?j))
(delete-char -1)
(set-buffer-modified-p modified)
(push 'escape unread-command-events))
(t (setq unread-command-events (append unread-command-events
(list evt))))))))
(define-key evil-insert-state-map (kbd "C-e") 'move-end-of-line)
(define-key evil-insert-state-map (kbd "C-k") 'kill-line)
(defun evilcvn-change-symbol-in-defun ()
"mark the region in defun (definition of function) and use string replacing UI in evil-mode
to replace the symbol under cursor"
(interactive)
(let ((old (thing-at-point 'symbol)))
(mark-defun)
(unless (evil-visual-state-p)
(evil-visual-state))
(evil-ex (concat "'<,'>s/" (if (= 0 (length old)) "" "\\<\\(") old (if (= 0 (length old)) "" "\\)\\>/"))))
)
(global-set-key (kbd "C-c ; s") 'evilcvn-change-symbol-in-defun)
;; {{ evil-leader config
(setq evil-leader/leader "," evil-leader/in-all-states t)
(require 'evil-leader)
(evil-leader/set-key
"cx" 'copy-to-x-clipboard
"px" 'paste-from-x-clipboard
"ci" 'evilnc-comment-or-uncomment-lines
"cl" 'evilnc-comment-or-uncomment-to-the-line
"cc" 'evilnc-copy-and-comment-lines
"ct" 'ctags-create-or-update-tags-table
"cs" 'evilcvn-change-symbol-in-defun
"t" 'ido-goto-symbol ;; same as my vim hotkey
"w" 'save-buffer
"cp" 'compile
"ud" '(lambda ()(interactive) (gud-gdb (concat "gdb --fullname " (cppcm-get-exe-path-current-buffer))))
"W" 'save-some-buffers
"K" 'kill-buffer-and-window
"it" 'issue-tracker-increment-issue-id-under-cursor
"bm" 'pomodoro-start ;; beat myself
"." 'evil-ex
;; toggle overview, @see http://emacs.wordpress.com/2007/01/16/quick-and-dirty-code-folding/
"ov" '(lambda () (interactive) (set-selective-display (if selective-display nil 1)))
"mq" '(lambda () (interactive) (man (concat "-k " (thing-at-point 'symbol))))
"gg" '(lambda () (interactive) (w3m-search "g" (thing-at-point 'symbol)))
"q" '(lambda () (interactive) (w3m-search "q" (thing-at-point 'symbol)))
"s1" 'delete-other-windows
"s2" 'split-window-below
"s3" 'split-window-right
"su" 'winner-undo
"hs" 'w3mext-hacker-search
"gf" 'gtags-find-tag-from-here
"gp" 'gtags-pop-stack
"gr" 'gtags-find-rtag
"gy" 'gtags-find-symbol
"cg" 'djcb-gtags-create-or-update
"bc" '(lambda () (interactive) (wxhelp-browse-class-or-api (thing-at-point 'symbol)))
"ma" 'mc/mark-all-like-this-in-defun
"mw" 'mc/mark-all-words-like-this-in-defun
"ms" 'mc/mark-all-symbols-like-this-in-defun
;; recommended in html
"md" 'mc/mark-all-like-this-dwim
"rw" 'rotate-windows
"l" 'align-regexp
"x" 'er/expand-region
"vd" 'scroll-other-window
"vu" '(lambda () (interactive) (scroll-other-window-down nil))
)
;; }}
;; change mode-line color by evil state
(lexical-let ((default-color (cons (face-background 'mode-line)
(face-foreground 'mode-line))))
(add-hook 'post-command-hook
(lambda ()
(let ((color (cond ((minibufferp) default-color)
((evil-insert-state-p) '("#e80000" . "#ffffff"))
((evil-emacs-state-p) '("#444488" . "#ffffff"))
((buffer-modified-p) '("#006fa0" . "#ffffff"))
(t default-color))))
(set-face-background 'mode-line (car color))
(set-face-foreground 'mode-line (cdr color))))))
;; comment/uncomment lines
(evilnc-default-hotkeys)
(provide 'init-evil)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cowboy13/emacs.git
git@gitee.com:cowboy13/emacs.git
cowboy13
emacs
emacs
master

搜索帮助