Emacs - eshell mapping
[dotfiles.git] / emacs.d / emacs-evil.org
index ca30b23..a1f26b5 100644 (file)
@@ -37,6 +37,16 @@ https://www.emacswiki.org/emacs/Evil.
                                 (modify-syntax-entry ?_ "w")
                                 ;; (modify-syntax-entry ?- "w")
                                 ))
+
+  (with-eval-after-load "evil"
+    ;; remap x to X as `evil-move-cursor-back' is set nil
+    ;; (define-key evil-normal-state-map [remap evil-delete-char] 'evil-delete-backward-char)
+    (define-key evil-normal-state-map (kbd "x") (lambda () (interactive)
+                                                  (let ((org evil-move-cursor-back))
+                                                    (setq evil-move-cursor-back t)
+                                                    (call-interactively 'evil-delete-char)
+                                                    ;; (evil-delete-char)
+                                                    (setq evil-move-cursor-back org)))))
 #+END_SRC
 
 ** Initial mode and state config
@@ -87,33 +97,6 @@ https://www.emacswiki.org/emacs/Evil.
     (evil-escape-mode))
 #+END_SRC
 
-* Evil-Leader
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (with-eval-after-load "evil-leader"
-    ;; Buffer & File
-    (evil-leader/set-key "f" 'ido-switch-buffer)
-    (evil-leader/set-key "w" 'evil-save)
-    (evil-leader/set-key "r" 'ivy-recentf)
-    (evil-leader/set-key "w" 'save-buffer)
-    (evil-leader/set-key "o" 'ido-find-file)
-    (evil-leader/set-key "p" 'projectile-find-file)
-    ;; Window
-    (evil-leader/set-key "s" 'evil-window-split)
-    (evil-leader/set-key "v" 'evil-window-vsplit)
-    (evil-leader/set-key "q" 'evil-quit)
-    ;; others
-    (evil-leader/set-key "h" 'help)
-    (evil-leader/set-key "g" 'magit-status)
-    (evil-leader/set-key "d" 'dired)
-    (evil-leader/set-key "e" 'sd/toggle-project-eshell))
-
-  (with-eval-after-load "evil"
-    (evil-define-key 'emacs eshell-mode-map (kbd ";e") 'sd/toggle-project-eshell)
-    (evil-define-key 'emacs eshell-mode-map (kbd ";d") 'dired)
-    (evil-define-key 'emacs eshell-mode-map (kbd "C-;") 'mode-line-other-buffer))
-
-#+END_SRC
-
 * other extention
 ** Evil-matchit
 [[https://github.com/redguardtoo/evil-matchit]]
@@ -142,8 +125,28 @@ https://www.emacswiki.org/emacs/Evil.
     (global-evil-surround-mode 1))
 #+END_SRC
 * Key bindings
+** Evil-Leader
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (with-eval-after-load "evil-leader"
+    ;; Buffer & File explore
+    (evil-leader/set-key "b" 'counsel-projectile-find-file)
+    (evil-leader/set-key "f" 'ivy-switch-buffer)
+    (evil-leader/set-key "r" 'ivy-recentf)
+    (evil-leader/set-key "w" 'save-buffer)
+    ;; Window
+    (evil-leader/set-key "s" 'evil-window-split)
+    (evil-leader/set-key "v" 'evil-window-vsplit)
+    (evil-leader/set-key "q" 'evil-quit)
+    ;; others
+    (evil-leader/set-key "g" 'magit-status)
+    ;; (evil-leader/set-key "d" (lambda () (interactive) (dired default-directory)))
+    (evil-leader/set-key "d" 'dired)
+    (evil-leader/set-key "e" 'sd/toggle-project-eshell)
+    (evil-leader/set-key "h" 'help))
+#+END_SRC
+** Basic state bindings
 There are three kinds key bindings
-- prefix key is the leader key, defined by evil-leader. *;*
+- prefix key is the leader key, defined by evil-leader.
 - prefix key is the =Ctrl=,
 - prefix key is =\=, 
 
@@ -187,7 +190,34 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
     (define-key evil-normal-state-map "\\\\" #'evil-ex-nohighlight))
 #+END_SRC
 
-- Dired mode
+** Eshell
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (add-hook 'eshell-mode-hook (lambda ()
+                                (when (and (boundp 'evil-mode) evil-mode)
+                                  (dolist (key-fun '(("f" . ivy-switch-buffer)
+                                                     ("b" . counsel-projectile-find-file)
+                                                     ("r" . counsel-recentf)
+                                                     ("e" . sd/toggle-project-eshell)
+                                                     ("d" . dired)
+                                                     ("'" . other-window)
+                                                     ("q" . evil-quit)))
+                                    (evil-define-key 'emacs eshell-mode-map (kbd (concat evil-leader/leader (car key-fun))) (cdr key-fun))))
+                                ;; (define-key eshell-mode-map (kbd "C-j") nil)
+                                ))
+
+  ;; 
+  ;; (add-hook 'eshell-mode-map
+  ;;        (lambda ()
+  ;;          (mapc (lambda (key-fun)
+  ;;                  (evil-define-key 'emacs eshell-mode-map (kbd (concat evil-leader/leader (car key-fun))) (cdr key-fun)))
+  ;;                '(("e" . dired)))))
+
+  ;; (add-hook 'eshell-mode-hook (lambda ()
+  ;;                               (loop for (key . fun) in '(
+  ;;                                                          ("e" . sd/toggle-project-eshell))
+  ;;                                     do (evil-define-key 'emacs eshell-mode-map (kbd (concat evil-leader/leader key)) fun))))
+#+END_SRC
+** Dired mode
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (with-eval-after-load "evil"
     ;; file and directory explore
@@ -228,7 +258,7 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
 
 #+END_SRC
 
-- expand region
+** expand region
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (with-eval-after-load "evil"
     (with-eval-after-load "expand-region"
@@ -238,6 +268,29 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
       (define-key evil-normal-state-map (kbd "S-SPC") 'er/contract-region)))
 #+END_SRC
 
+** Org Mode (worf mode) and Lispy mode
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (with-eval-after-load "evil"
+    (with-eval-after-load "lispy"
+      (evil-define-key 'normal lispy-mode-map (kbd "[") (lambda ()
+                                                          (interactive)
+                                                          (call-interactively #'lispy-backward)
+                                                          (evil-emacs-state)))
+      (evil-define-key 'normal lispy-mode-map (kbd "]") (lambda ()
+                                                          (interactive)
+                                                          (call-interactively #'lispy-forward)
+                                                          (evil-emacs-state))))
+    (with-eval-after-load "worf"
+      (evil-define-key 'normal worf-mode-map (kbd "[") (lambda ()
+                                                         (interactive)
+                                                         (call-interactively #'worf-backward)
+                                                         (evil-emacs-state)))
+      (evil-define-key 'normal worf-mode-map (kbd "]") (lambda ()
+                                                         (interactive)
+                                                         (call-interactively #'worf-forward)
+                                                         (evil-emacs-state)))))
+#+END_SRC
+
 * Others
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (dolist (mode '(c-mode-hook lua-mode-hook))