2020-11-18 00:51:00 +01:00
|
|
|
* Evil
|
2020-11-01 02:56:34 +01:00
|
|
|
#+NAME: evil
|
2020-11-18 00:51:00 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp :tangle yes
|
2020-11-04 21:10:07 +01:00
|
|
|
(use-package evil
|
|
|
|
:ensure t
|
|
|
|
:init
|
|
|
|
(setq evil-want-keybinding nil)
|
|
|
|
:bind (:map evil-motion-state-map
|
|
|
|
("h" . nil)
|
|
|
|
("j" . evil-backward-char)
|
|
|
|
("k" . evil-previous-line)
|
|
|
|
("l" . evil-next-line)
|
|
|
|
(";" . evil-forward-char)
|
|
|
|
:map evil-motion-state-map
|
|
|
|
("<left>" . (lambda () (interactive) ()))
|
|
|
|
("<right>" . (lambda () (interactive) ()))
|
|
|
|
("<up>" . (lambda () (interactive) ()))
|
|
|
|
("<down>" . (lambda () (interactive) ()))
|
|
|
|
:map evil-insert-state-map
|
|
|
|
("<left>" . (lambda () (interactive) ()))
|
|
|
|
("<right>" . (lambda () (interactive) ()))
|
|
|
|
("<up>" . (lambda () (interactive) ()))
|
|
|
|
("<down>" . (lambda () (interactive) ())))
|
|
|
|
:config
|
|
|
|
(evil-mode 1)
|
|
|
|
(with-eval-after-load "treemacs"
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "h") nil)
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "j") 'treemacs-root-up)
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "k") 'treemacs-previous-line)
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "l") 'treemacs-next-line)
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd ";") 'treemacs-root-down))
|
|
|
|
;; :q should kill the current buffer rather than quitting emacs entirely
|
|
|
|
(evil-ex-define-cmd "q" 'kill-this-buffer)
|
|
|
|
;; Need to type out :quit to close emacs
|
|
|
|
(evil-ex-define-cmd "quit" 'evil-quit)
|
|
|
|
;; save and close buffer
|
|
|
|
(defun liu233w/ex-save-kill-buffer-and-close ()
|
|
|
|
(interactive)
|
|
|
|
(save-buffer)
|
|
|
|
(kill-this-buffer))
|
|
|
|
(evil-ex-define-cmd "wq" 'liu233w/ex-save-kill-buffer-and-close))
|
2020-11-01 02:56:34 +01:00
|
|
|
|
2020-11-04 21:10:07 +01:00
|
|
|
(use-package evil-collection
|
|
|
|
:ensure t
|
|
|
|
:config
|
|
|
|
(evil-collection-init 'vterm)
|
|
|
|
(defun evil-collection-vterm-escape-stay ()
|
|
|
|
"Go back to normal state but don't move cursor backwards.
|
|
|
|
Moving cursor backwards is the default vim behavior but
|
|
|
|
it is not appropriate in some cases like terminals."
|
|
|
|
(setq-local evil-move-cursor-back nil))
|
2020-11-01 02:56:34 +01:00
|
|
|
|
2020-11-04 21:10:07 +01:00
|
|
|
(add-hook 'vterm-mode-hook #'evil-collection-vterm-escape-stay))
|
2020-11-01 02:56:34 +01:00
|
|
|
|
2020-11-04 21:10:07 +01:00
|
|
|
(use-package evil-surround
|
|
|
|
:ensure t
|
|
|
|
:after evil
|
|
|
|
:config
|
|
|
|
(global-evil-surround-mode 1))
|
2020-11-01 02:56:34 +01:00
|
|
|
|
2020-11-04 21:10:07 +01:00
|
|
|
(use-package key-chord
|
|
|
|
:ensure t
|
|
|
|
:config
|
|
|
|
(defun magic_rb/key-chord-define-nonsymmetric (keymap keys command)
|
|
|
|
(if (/= 2 (length keys))
|
|
|
|
(error "Key-chord keys must have two elements"))
|
|
|
|
(let ((key1 (logand 255 (aref keys 0)))
|
|
|
|
(key2 (logand 255 (aref keys 1))))
|
|
|
|
(if (eq key1 key2)
|
2020-11-01 02:56:34 +01:00
|
|
|
(define-key keymap (vector 'key-chord key1 key2) command)
|
2020-11-04 21:10:07 +01:00
|
|
|
(define-key keymap (vector 'key-chord key1 key2) command)
|
|
|
|
)))
|
|
|
|
(setq key-chord-two-keys-delay 0.15)
|
|
|
|
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
|
|
|
|
(key-chord-mode 1))
|
2020-11-01 02:56:34 +01:00
|
|
|
#+END_SRC
|