2022-11-28 12:23:27 +01:00
|
|
|
;;; init-evil.el --- VIM dentro de emacs -*- lexical-binding: t -*-
|
|
|
|
|
|
|
|
;; Author: kj <webmaster@outcontrol.net>
|
|
|
|
;; URL: https://git.kj2.me/kj/confi-emacs-actual
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2023-04-14 18:39:19 +02:00
|
|
|
;; En este archivo está toda la configuración relacionada
|
|
|
|
;; con el paquete Evil.
|
|
|
|
;;
|
|
|
|
;; Evil es un paquete para Emacs, que básicamente nos
|
|
|
|
;; permite tener VIM dentro de Emacs.
|
|
|
|
|
2022-11-28 12:23:27 +01:00
|
|
|
;;; Code:
|
|
|
|
(use-package evil
|
|
|
|
:defer t
|
2024-03-25 05:19:55 +01:00
|
|
|
:hook (elpaca-after-init . evil-mode)
|
2022-11-28 12:23:27 +01:00
|
|
|
:config
|
2022-11-29 08:46:08 +01:00
|
|
|
;; Configuraciones básicas
|
2023-09-23 23:32:38 +02:00
|
|
|
;; (setq evil-default-state 'emacs) ;; Modo por defecto en emacs
|
2024-03-25 05:24:32 +01:00
|
|
|
(setq evil-default-state 'insert) ;; Modo por defecto en emacs
|
2022-11-29 08:46:08 +01:00
|
|
|
(setq evil-emacs-state-cursor 'bar) ;; Cursor de emacs state en bar
|
2024-04-12 14:13:16 +02:00
|
|
|
;; (setq evil-normal-state-cursor 'bar) ;; Cursor de normal state en bar en lugar de box
|
2022-11-29 08:46:08 +01:00
|
|
|
(evil-set-leader 'motion (kbd "SPC")) ;; Leader key
|
2023-01-22 03:38:30 +01:00
|
|
|
(evil-set-undo-system 'undo-redo)
|
2022-11-28 12:23:27 +01:00
|
|
|
|
2022-11-29 08:46:08 +01:00
|
|
|
;; Habilitar atajos de de tecla de emacs en insert state
|
|
|
|
(setq evil-insert-state-map (make-sparse-keymap))
|
2023-01-22 03:11:44 +01:00
|
|
|
|
2024-03-25 05:22:56 +01:00
|
|
|
;; (evil-define-key 'normal 'global (kbd "<escape>") 'corfu-quit)
|
|
|
|
;; Cambiar a mode emacs con escape
|
2023-01-22 03:11:44 +01:00
|
|
|
;; (evil-define-key 'emacs 'global (kbd "<escape>") 'evil-normal-state)
|
|
|
|
;; Cambiar Insert state por emacs state.
|
|
|
|
;; (defalias 'evil-insert-state 'evil-emacs-state)
|
2022-11-28 12:23:27 +01:00
|
|
|
|
2023-01-22 03:11:44 +01:00
|
|
|
;; Variales locales (todos los estados o solo los estados de VIM)
|
2022-11-29 08:46:08 +01:00
|
|
|
(setq all-states '(normal insert visual replace operator motion emacs))
|
|
|
|
(setq vim-states '(normal insert visual replace operator motion))
|
|
|
|
|
2023-01-22 03:11:44 +01:00
|
|
|
;; Cambiar entre modo emacs y evil (Mi pripio evil toggle)
|
2023-10-14 16:29:55 +02:00
|
|
|
;; (evil-define-key vim-states 'global (kbd "C-'") 'evil-emacs-state)
|
|
|
|
;; (evil-define-key 'emacs 'global (kbd "C-'") 'evil-normal-state)
|
2022-11-29 08:46:08 +01:00
|
|
|
|
2023-01-22 03:38:30 +01:00
|
|
|
;; Cambiar C-z a deshacer
|
|
|
|
(evil-define-key all-states 'global (kbd "C-z") 'undo)
|
|
|
|
|
|
|
|
;; Cambiar C-r a ripgrep y U hasta hacer redo
|
2023-10-14 16:29:55 +02:00
|
|
|
(evil-define-key vim-states 'global (kbd "C-r") 'consult-ripgrep)
|
2023-01-22 03:38:30 +01:00
|
|
|
(evil-define-key 'normal 'global (kbd "U") 'undo-redo)
|
2023-10-14 16:29:55 +02:00
|
|
|
(evil-define-key 'normal 'global (kbd "C-S-z") 'undo-redo)
|
2024-03-25 05:22:56 +01:00
|
|
|
(evil-define-key 'normal 'global (kbd "M-.") 'xref-find-definitions)
|
2023-01-22 03:38:30 +01:00
|
|
|
|
2023-03-24 19:53:41 +01:00
|
|
|
;; Arreglar yank-pop en normal mode
|
2023-10-14 16:29:55 +02:00
|
|
|
(evil-define-key 'normal 'global (kbd "M-y") 'consult-yank-pop)
|
2023-03-24 19:53:41 +01:00
|
|
|
|
2023-08-22 06:45:24 +02:00
|
|
|
;; Re-bindear keys a como funcionan en emacs.
|
2023-03-24 19:53:41 +01:00
|
|
|
(evil-define-key 'normal 'global (kbd "C-p") 'previous-line)
|
|
|
|
(evil-define-key 'normal 'global (kbd "C-n") 'next-line)
|
2023-08-22 06:45:24 +02:00
|
|
|
(evil-define-key 'normal 'global (kbd "C-e") 'move-end-of-line)
|
2023-03-24 19:53:41 +01:00
|
|
|
|
2022-11-29 08:46:08 +01:00
|
|
|
;; Navegación entre frames
|
2024-03-25 05:22:56 +01:00
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>o") 'other-window)
|
2022-11-29 08:46:08 +01:00
|
|
|
|
2024-04-13 22:21:05 +02:00
|
|
|
;; Habilitar el scrolear con C-v como en emacs en evil
|
|
|
|
(evil-define-key 'motion 'global (kbd "C-v") 'scroll-up-command)
|
|
|
|
|
2024-03-29 03:06:24 +01:00
|
|
|
;; Añadir nueva linea sin salir del modo normal
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader><RET>") 'newline)
|
|
|
|
|
2024-03-29 03:48:59 +01:00
|
|
|
;; Abrir historial del kill-ring/portapapeles
|
|
|
|
(evil-define-key vim-states 'global (kbd "<leader>y") 'consult-yank-pop)
|
|
|
|
|
|
|
|
;; Expand region desde motion states
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>+") 'er/expand-region)
|
|
|
|
|
|
|
|
;; Identado en motion modes.
|
|
|
|
(evil-define-key 'motion 'global (kbd "<tab>") 'indent-for-tab-command)
|
|
|
|
|
2022-11-29 08:46:08 +01:00
|
|
|
;; Atajos con leader key para frames
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>0") 'delete-window)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>1") 'delete-other-windows)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>2") 'split-window-below)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>3") 'split-window-right)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>k") 'kill-buffer)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>wu") 'winner-undo)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>wr") 'winner-redo)
|
|
|
|
|
|
|
|
;; Cambios de modos
|
|
|
|
(evil-define-key 'normal 'global (kbd "<leader>mh") 'html-mode)
|
|
|
|
(evil-define-key 'normal 'global (kbd "<leader>mj") 'js-mode)
|
|
|
|
(evil-define-key 'normal 'global (kbd "<leader>mp") 'php-mode)
|
|
|
|
(evil-define-key 'normal 'global (kbd "<leader>mr") 'rust-mode)
|
|
|
|
(evil-define-key 'normal 'global (kbd "<leader>mw") 'web-mode)
|
|
|
|
|
|
|
|
;; Otros atajos
|
2024-03-25 05:22:56 +01:00
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>xb") 'consult-buffer) ;; Cambiar de buffer
|
2024-04-14 01:02:22 +02:00
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>xp") 'consult-project-extra-find) ;; Archivos del proyecto (o abrir proyecto si no hay alguno)
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>cp") 'project-switch-project) ;; Cambiar proyecto
|
2024-03-25 05:22:56 +01:00
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>xf") 'find-file) ;; Abrir archivo
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>xr") 'consult-recent-file) ;; Lista de archivos recientes
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>rg") 'consult-ripgrep) ;; Búsqueda rápida con ripgrep
|
|
|
|
(evil-define-key 'motion 'global (kbd "<leader>gi") 'imenu) ;; imenu
|
2022-11-29 08:46:08 +01:00
|
|
|
|
2023-06-17 12:13:53 +02:00
|
|
|
;; Iniciar en normal state si es un lenguaje de programación u org-mode
|
2023-04-14 02:40:26 +02:00
|
|
|
;; (evil-set-initial-state 'prog-mode 'normal)
|
|
|
|
;; (evil-set-initial-state 'org-mode 'normal)
|
2024-03-29 17:41:41 +01:00
|
|
|
(evil-set-initial-state 'dashboard-mode 'normal)
|
2023-08-22 06:45:24 +02:00
|
|
|
(evil-set-initial-state 'dired 'normal)
|
2024-03-25 05:22:56 +01:00
|
|
|
(evil-set-initial-state 'vterm-mode 'emacs)
|
2022-11-28 12:23:27 +01:00
|
|
|
)
|
|
|
|
|
2024-04-06 20:42:25 +02:00
|
|
|
;; Funciones y atajos de teclas especiales para evil cuando estamo en org-mode.
|
|
|
|
;; Por ejemplo, para que evil-open-below funcione similar a org-return cuando
|
|
|
|
;; estamos dentro de una lista.
|
|
|
|
(use-package evil-org
|
|
|
|
:ensure t
|
|
|
|
:defer t
|
|
|
|
:after org
|
|
|
|
:hook (org-mode . evil-org-mode))
|
|
|
|
|
2022-11-28 12:23:27 +01:00
|
|
|
(provide 'init-evil)
|
|
|
|
;;; init-evil.el ends here
|