dotfiles/emacs-lisp/evil.org
main c1dc0c1d7f
Move keybindings related Emacs config to separate file
Signed-off-by: main <magic_rb@redalder.org>
2022-04-15 09:50:18 +02:00

1.5 KiB

Evil Mode

Evil is an extensible vi layer for Emacs. It emulates the main features of Vim, and provides facilities for writing custom extensions.

This requires general.el.

  (use-package evil
    :straight t
    :init
    (setq evil-want-keybinding nil)
    :config
    (setq evil-respect-visual-line-mode t)
    (evil-mode)
    ;; :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
    :after (evil vterm)
    :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))