Emacs - Counsel & Ivy & Swiper
authorPeng Li <seudut@gmail.com>
Mon, 25 Sep 2017 15:15:47 +0000 (23:15 +0800)
committerPeng Li <seudut@gmail.com>
Tue, 26 Sep 2017 18:30:49 +0000 (02:30 +0800)
emacs.d/config.org
emacs.d/emacs-evil.org

index aa75064..c80ebdb 100644 (file)
@@ -685,27 +685,75 @@ Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for
                   ido-file-dir-completion-map)))
 #+END_SRC
 
-** Counsel
+** helm
+let helm windows split inside current window
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (with-eval-after-load 'helm
+    (setq helm-split-window-in-side-p t))
+#+END_SRC
+
+* Swiper & Ivy & Counsel
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
   (use-package counsel
     :ensure t
     :defer t
     :init
+    (use-package ivy :ensure t)
+    (ivy-mode 1)
+    (setq ivy-use-virtual-buffers nil
+          ivy-wrap t)
+    (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
     (global-set-key (kbd "M-x") 'counsel-M-x)
     (global-set-key (kbd "C-h f") 'counsel-describe-function)
     (global-set-key (kbd "C-h v") 'counsel-describe-variable)
-    ;; (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
+    (global-set-key (kbd "C-x C-f") 'counsel-find-file)
     (define-key read-expression-map (kbd "C-r") 'counsel-expression-history)
     (global-set-key (kbd "C-c C-r") 'ivy-resume))
+
+  (use-package counsel-projectile
+    :ensure t
+    :defer t)
 #+END_SRC
 
-** helm
-let helm windows split inside current window
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (with-eval-after-load 'helm
-    (setq helm-split-window-in-side-p t))
+  (defun sd/swith-buffer-other-window ()
+    (interactive)
+    (ivy-set-action (cond ((eq (ivy-state-caller ivy-last) 'ivy-switch-buffer)
+                           'ivy--switch-buffer-other-window-action)
+                          ((eq (ivy-state-caller ivy-last) 'counsel-recentf)
+                           'find-file-other-window)
+                          ((eq (ivy-state-caller ivy-last) 'counsel-projectile-find-file)
+                           'counsel-projectile-find-file-action-other-window)
+                          (t
+                           nil)))
+    (ivy-done)
+    (ivy-shrink-after-dispatching))
+
+  (with-eval-after-load "ivy"
+    (define-key ivy-minibuffer-map (kbd "C-k") #'sd/swith-buffer-other-window))
 #+END_SRC
 
+stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+  (use-package swiper
+    :ensure t
+    ;; :init
+    ;(require 'ivy)
+    ;; (setq ivy-use-virtual-buffers nil)
+    ;; (setq ivy-wrap t)
+    ;(set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
+    :config
+    ;; (ivy-mode)
+    (global-set-key (kbd "s-/") 'swiper)
+    (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
+    (define-key swiper-map (kbd "C-.") (lambda ()
+                                         (interactive)
+                                         (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
+    (define-key swiper-map (kbd "M-.") (lambda ()
+                                         (interactive)
+                                         (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
+
+#+END_SRC
 * Org-mode Settings
 ** Org-mode Basic setting
 Always indents header, and hide header leading starts so that no need type =#+STATUP: indent= 
@@ -3581,29 +3629,6 @@ Occur search key bindings
     (use-package moccur-edit))
 #+END_SRC
 
-*** Swiper
-stolen from [[https://github.com/mariolong/emacs.d/blob/f6a061594ef1b5d1f4750e9dad9dc97d6e122840/emacs-init.org][here]]
-#+BEGIN_SRC emacs-lisp :tangle yes :results silent
-  (use-package swiper
-    :ensure t
-    :init
-    (setq ivy-use-virtual-buffers nil)
-    (setq ivy-wrap t)
-    (set-face-attribute 'ivy-current-match nil :background "Orange" :foreground "black")
-    :config
-    (ivy-mode)
-    (global-set-key (kbd "s-/") 'swiper)
-    (define-key swiper-map (kbd "M-r") 'swiper-query-replace)
-    (define-key swiper-map (kbd "C-.") (lambda ()
-                                         (interactive)
-                                         (insert (format "%s" (with-ivy-window (thing-at-point 'word))))))
-    (define-key swiper-map (kbd "M-.") (lambda ()
-                                         (interactive)
-                                         (insert (format "%s" (with-ivy-window (thing-at-point 'symbol)))))))
-
-  (with-eval-after-load "ivy"
-    (define-key ivy-minibuffer-map (kbd "C-o") 'ivy-dispatching-done))
-#+END_SRC
 
 ** Expand region map
 *** Install =expand-region=
index 8c91ebc..b66817a 100644 (file)
@@ -124,8 +124,6 @@ https://www.emacswiki.org/emacs/Evil.
     :config
     (global-evil-surround-mode 1))
 #+END_SRC
-
-
 * Key bindings
 ** Evil-Leader
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
@@ -204,7 +202,7 @@ Let the search highlight persistent, https://stackoverflow.com/questions/2576803
   (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)
+                                                     ;("b" . counsel-projectile-find-file)
                                                      ("r" . counsel-recentf)
                                                      ("e" . sd/toggle-project-eshell)
                                                      ("d" . dired)