2020-12-26 23:36:50 +01:00
|
|
|
* Evil
|
|
|
|
#+NAME: evil
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(use-package evil
|
|
|
|
:straight 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
|
2021-01-07 16:07:05 +01:00
|
|
|
("<left>" . 'ignore)
|
|
|
|
("<right>" . 'ignore)
|
|
|
|
("<up>" . 'ignore)
|
|
|
|
("<down>" . 'ignore)
|
2020-12-26 23:36:50 +01:00
|
|
|
:map evil-insert-state-map
|
2021-01-07 16:07:05 +01:00
|
|
|
("<left>" . 'ignore)
|
|
|
|
("<right>" . 'ignore)
|
|
|
|
("<up>" . 'ignore)
|
2021-01-10 20:20:06 +01:00
|
|
|
("<down>" . 'ignore))
|
2020-12-26 23:36:50 +01:00
|
|
|
:config
|
|
|
|
(evil-mode 1)
|
|
|
|
(with-eval-after-load "treemacs"
|
2021-01-07 16:07:05 +01:00
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "h") 'ignore)
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "j") 'ignore)
|
2020-12-26 23:36:50 +01:00
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "k") 'treemacs-previous-line)
|
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd "l") 'treemacs-next-line)
|
2021-01-07 16:07:05 +01:00
|
|
|
(evil-define-key 'treemacs treemacs-mode-map (kbd ";") 'ignore))
|
2020-12-26 23:36:50 +01:00
|
|
|
;; :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))
|
|
|
|
|
|
|
|
(use-package evil-collection
|
|
|
|
:straight 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))
|
|
|
|
|
|
|
|
(add-hook 'vterm-mode-hook #'evil-collection-vterm-escape-stay))
|
|
|
|
|
|
|
|
(use-package evil-surround
|
|
|
|
:straight t
|
|
|
|
:after evil
|
|
|
|
:config
|
|
|
|
(global-evil-surround-mode 1))
|
|
|
|
|
|
|
|
(use-package key-chord
|
|
|
|
:straight 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)
|
|
|
|
(define-key keymap (vector 'key-chord key1 key2) command)
|
|
|
|
(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))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Evil org-mode
|
|
|
|
#+NAME: evil-ord-mode
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(use-package evil-org
|
|
|
|
:straight t
|
|
|
|
:after org
|
|
|
|
:config
|
|
|
|
(add-hook 'org-mode-hook 'evil-org-mode)
|
|
|
|
(add-hook 'evil-org-mode-hook
|
|
|
|
(lambda ()
|
|
|
|
(evil-org-set-key-theme)))
|
|
|
|
(require 'evil-org-agenda)
|
|
|
|
(evil-org-agenda-set-keys)
|
|
|
|
(evil-define-key 'motion org-agenda-mode-map (kbd "h") nil)
|
|
|
|
(evil-define-key 'motion org-agenda-mode-map (kbd "j") 'evil-backward-char)
|
|
|
|
(evil-define-key 'motion org-agenda-mode-map (kbd "k") 'org-agenda-previous-line)
|
|
|
|
(evil-define-key 'motion org-agenda-mode-map (kbd "l") 'org-agenda-next-line))
|
|
|
|
#+END_SRC
|
2021-01-07 16:07:05 +01:00
|
|
|
|
|
|
|
** Evil Window Movement
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(with-eval-after-load "evil"
|
|
|
|
(define-prefix-command 'evil-window-movement-map)
|
|
|
|
(let ((map evil-window-movement-map))
|
|
|
|
(define-key map "j" 'evil-window-left)
|
|
|
|
(define-key map "k" 'evil-window-up)
|
|
|
|
(define-key map "l" 'evil-window-down)
|
|
|
|
(define-key map ";" 'evil-window-right)
|
|
|
|
|
|
|
|
(define-key map "J" 'evil-window-move-far-left)
|
|
|
|
(define-key map "K" 'evil-window-move-very-top)
|
|
|
|
(define-key map "L" 'evil-window-move-very-bottom)
|
|
|
|
(define-key map ":" 'evil-window-move-far-right)
|
|
|
|
|
|
|
|
(define-key map "v" 'evil-window-vsplit)
|
|
|
|
(define-key map "s" 'evil-window-split)
|
|
|
|
(define-key map "x" 'evil-window-delete))
|
|
|
|
(define-key evil-motion-state-map " " 'evil-window-movement-map)
|
|
|
|
(with-eval-after-load "treemacs-evil"
|
|
|
|
(define-key evil-treemacs-state-map " " 'evil-window-movement-map)))
|
|
|
|
#+END_SRC
|