A series of notes that I learn Emacs hacking. Introduction to evil-mode, packages to augment evil, such as evil-leader, eveil-surrond, evil-nerd-commenter, powerline-evil; misc. improvement, such as window-numbering, which-key and powerline packages.
Use Evil to enable
- aka “Extensible vi layer for Emacs”.
- In the
init-packages.el, add the configuration below
(evil-mode 1) (setcdr evil-insert-state-map nil) (define-key evil-insert-state-map [escape] 'evil-normal-state)
- Some difference between
C-d to page down, but
C-u does not page up. Because
C-u is used as “Universal args” in Emacs. We can change this in
- PDF manual for user switching from vim to Emacs. Evil.pdf.
- Evil state = Emacs mode
- evil normal state
- evail insert state
- evil visual state
- evil motion state
- evil emacs state
- evil operator state (diw)
We want to set the evil state when we enter certain mode, use the following code
(dolist (mode '(ag-mode flycheck-error-list-mode occur-mode git-rebase-mode )) (add-to-list 'evil-emacs-state-mode mode))
- Enable key binding in certain mode
(add-hook 'occur-mode-hook (lambda () (evil-add-hjkl-bindings occur-mode-map 'emacs (kbd "/") 'evil-search-forward (kbd "n") 'evil-search-next (kbd "N") 'evil-search-previous (kbd "C-d") 'evil-scroll-down (kbd "C-u") 'evil-scroll-up )))
- Add more plugins to customize
(global-evil-leader-mode)Helps to add short key to evil normal state. Add as much key bindings as you like.
(evil-leader/set-keyword "ff" 'find-file "fr" 'recentf-open-files "bs" 'switch-to-buffer "bk" 'kill-buffer "pf" 'counsel-git "ps" 'helm-do-ag-project-root "0" 'select-window-0 "1" 'select-window-1 "2" 'select-window-2 "3" 'select-window-3 "w/" 'split-window-right "w-" 'split-window-below "wo" 'delete-other-windows ":" 'counsel-M-x )
evil-surroundpackage. When you select a word and type something, the word will be surrounded by that.
evil-nerd-commenterpackage. We can add comment or remove the comment of current section. Add toggle comment line to visual state and normal state:
(define-key evil-normal-state-map (kbd ",/") 'evilnc-comment-or-uncomment-lines) (define-key evil-visual-state-map (kbd ",/") 'evilnc-comment-or-uncomment-lines)
powerline-evilpackage. A powerline minor mode for the evil mode. Try to add window number to the powerline, but failed. In the video, window numbering is finally enabled without loading the powerline.
C-w to delete a word backward
(global-set-key (kbd "C-w") 'backward-kill-word)
- Polish the mode line, make it special and beautiful.
(require which-key) (which-key-mode 1)
- Set popup window properties
(setq which-key-side-window-max-height 0.25) (setq which-key-side-window-location 'right)
Search in org agenda
C-aenter agenda mode.
- Read the key in list for details.