1 #+TITLE: Ivy User Manual
3 #+EMAIL: ohwoeowho@gmail.com
6 #+TEXINFO_DIR_CATEGORY: Emacs
7 #+TEXINFO_DIR_TITLE: Ivy: (ivy).
8 #+TEXINFO_DIR_DESC: Using Ivy for completion.
9 #+SETUPFILE: ~/git/org-html-themes/setup/theme-readtheorg.setup
10 #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="kbd-style.css"/>
11 #+EXPORT_FILE_NAME: index.html
13 #+OPTIONS: H:6 num:6 toc:4
16 #+BEGIN_SRC elisp :exports results :results silent
17 (add-to-list 'load-path default-directory)
20 * Writing this manual :noexport:
21 For highlighting a section without introducing a new subheading use
22 definition lists. The definition list "owns" the following text if the
23 text is indented by 5 spaces. Use ~C-q~ to indent these
24 paragraphs. New paragraphs can also be started, as long as they have
27 For declaring a =@defopt= section for =defcustom= or =defvar=, also
28 use definition lists. They need to have the following form in order to
29 be recognized in the texinfo export:
32 User Option =ivy-wrap= ::
35 To name each heading, set its =CUSTOM_ID= property. This can be done
36 easily with =worf='s ~C-u L~.
44 Ivy manual, version 0.7.0
46 Ivy is an interactive interface for completion in Emacs. Emacs uses
47 completion mechanism in a variety of contexts: code, menus, commands,
48 variables, functions, etc. Completion entails listing, sorting,
49 filtering, previewing, and applying actions on selected items. When
50 active, =ivy-mode= completes the selection process by narrowing
51 available choices while previewing in the minibuffer. Selecting the
52 final candidate is either through simple keyboard character inputs or
53 through powerful regular expressions.
54 #+TEXINFO: @end ifnottex
56 Copyright (C) 2015 Free Software Foundation, Inc.
59 Permission is granted to copy, distribute and/or modify this document
60 under the terms of the GNU Free Documentation License, Version 1.3 or
61 any later version published by the Free Software Foundation; with no
62 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
63 and with the Back-Cover Texts as in (a) below. A copy of the license
64 is included in the section entitled ``GNU Free Documentation License.''
66 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
67 modify this GNU manual.''
70 #+HTML: <a href="https://github.com/abo-abo/swiper/blob/master/doc/ivy.org">This manual source</a>
73 :CUSTOM_ID: introduction
75 Ivy is for quick and easy selection from a list. When Emacs prompts
76 for a string from a list of several possible choices, Ivy springs into
77 action to assist in narrowing and picking the right string from a vast
80 Ivy strives for minimalism, simplicity, customizability and
84 Uncluttered minibuffer is minimalism. Ivy shows the completion
85 defaults, the number of matches, and 10 candidate matches below
86 the input line. Customize =ivy-length= to adjust the number of
87 candidate matches displayed in the minibuffer.
90 Simplicity is about Ivy's behavior in the minibuffer. It is also
91 about the code interface to extend Ivy's functionality. The
92 minibuffer area behaves as close to =fundamental-mode= as
93 possible. ~SPC~ inserts a space, for example, instead of being
94 bound to the more complex =minibuffer-complete-word=. Ivy's code
95 uses easy-to-examine global variables; avoids needless
96 complications with branch-introducing custom macros.
99 Customizability is about being able to use different methods and
100 interfaces of completion to tailor the selection process. For
101 example, adding a custom display function that points to a
102 selected candidate with =->=, instead of highlighting the
103 selected candidate with the =ivy-current-match= face. Or take the
104 customization of actions, say after the candidate function is
105 selected. ~RET~ uses =counsel-describe-function= to describe the
106 function, whereas ~M-o d~ jumps to that function's definition in
107 the code. The ~M-o~ prefix can be uniformly used with characters
108 like ~d~ to group similar actions.
111 Ivy displays easily discoverable commands through the hydra
112 facility. ~C-o~ in the minibuffer displays a hydra menu. It
113 opens up within an expanded minibuffer area. Each menu item comes
114 with short documentation strings and highlighted one-key
115 completions. So discovering even seldom used keys is simply a
116 matter of ~C-o~ in the minibuffer while in the midst of the Ivy
117 interaction. This discoverability minimizes exiting Ivy interface
118 for documentation look-ups.
122 :CUSTOM_ID: installation
125 Install Ivy automatically through Emacs's package manager, or manually
126 from Ivy's development repository.
128 ** Installing from Emacs Package Manager
130 :CUSTOM_ID: installing-from-emacs-package-manager
133 ~M-x~ =package-install= ~RET~ =swiper= ~RET~
135 Ivy is installed as part of =swiper= package. =swiper= is available
136 from two different package archives, GNU ELPA and MELPA. For the
137 latest stable version, use the GNU ELPA archives using the above M-x
140 For current hourly builds, use the MELPA archives. See the code below
141 for adding MELPA to the list of package archives:
145 (add-to-list 'package-archives
146 '("melpa" . "http://melpa.org/packages/"))
149 After this do ~M-x~ =package-refresh-contents= ~RET~, followed by
150 ~M-x~ =package-install= ~RET~ =swiper= ~RET~.
152 For package manager details, see [[info:emacs#Packages]].
154 ** Installing from the Git repository
156 :CUSTOM_ID: installing-from-the-git-repository
159 Why install from Git?
161 - No need to wait for MELPA's hourly builds
162 - Easy to revert to previous versions
163 - Contribute to Ivy's development; send patches; pull requests
165 *Configuration steps*
167 First clone the Swiper repository:
169 cd ~/git && git clone https://github.com/abo-abo/swiper
170 cd swiper && make compile
173 Then add this to Emacs init:
175 (add-to-list 'load-path "~/git/swiper/")
187 :CUSTOM_ID: getting-started
189 First, enable Ivy completion everywhere:
195 Note: =ivy-mode= can be toggled on and off with ~M-x~ =ivy-mode=.
196 ** Basic customization
198 :CUSTOM_ID: basic-customization
200 Here are some basic settings particularly useful for new Ivy
203 (setq ivy-use-virtual-buffers t)
205 (setq ivy-display-style 'fancy)
206 (setq ivy-count-format "(%d/%d) ")
209 For additional customizations, refer to =M-x describe-variable=
214 :CUSTOM_ID: key-bindings
216 ** Global key bindings
218 :CUSTOM_ID: global-key-bindings
220 The recommended key bindings are:
222 - Ivy-based interface to standard commands ::
224 (global-set-key (kbd "C-s") 'swiper)
225 (global-set-key (kbd "M-x") 'counsel-M-x)
226 (global-set-key (kbd "C-x C-f") 'counsel-find-file)
227 (global-set-key (kbd "<f1> f") 'counsel-describe-function)
228 (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
229 (global-set-key (kbd "<f1> l") 'counsel-load-library)
230 (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
231 (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
234 - Ivy-based interface to shell and system tools ::
236 (global-set-key (kbd "C-c g") 'counsel-git)
237 (global-set-key (kbd "C-c j") 'counsel-git-grep)
238 (global-set-key (kbd "C-c k") 'counsel-ag)
239 (global-set-key (kbd "C-x l") 'counsel-locate)
240 (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
243 - Ivy-resume and other commands ::
244 =ivy-resume= resumes the last Ivy-based completion.
246 (global-set-key (kbd "C-c C-r") 'ivy-resume)
249 ** Minibuffer key bindings
251 :CUSTOM_ID: minibuffer-key-bindings
254 Ivy includes several minibuffer bindings, which are defined in the
255 =ivy-minibuffer-map= keymap variable. The most frequently used ones
258 =swiper= or =counsel-M-x= add more through the =keymap= argument to
259 =ivy-read=. These keys, also active in the minibuffer, are described
260 under their respective commands.
262 *** Key bindings for navigation
264 :CUSTOM_ID: key-bindings-for-navigation
267 - ~C-n~ (=ivy-next-line=) selects the next candidate
268 - ~C-p~ (=ivy-previous-line=) selects the previous candidate
269 - ~M-<~ (=ivy-beginning-of-buffer=) selects the first candidate
270 - ~M->~ (=ivy-end-of-buffer=) selects the last candidate
271 - ~C-v~ (=ivy-scroll-up-command=) scrolls up by =ivy-height= lines
272 - ~M-v~ (=ivy-scroll-down-command=) scrolls down by =ivy-height= lines
275 - User Option =ivy-wrap= ::
276 This user option allows to get the wrap-around behavior for ~C-n~
277 and ~C-p~. When set to =t=, =ivy-next-line= and
278 =ivy-previous-line= will cycle past the last and the first
279 candidates respectively.
281 This behavior is off by default.
283 - User Option =ivy-height= ::
284 Use this variable to adjust the minibuffer height, and therefore
285 the scroll size for ~C-v~ and ~M-v~.
288 *** Key bindings for single selection, action, then exit minibuffer
290 :CUSTOM_ID: key-bindings-for-single-selection-action-then-exit-minibuffer
293 Ivy can offer several actions from which to choose which action to
294 run. This "calling an action" operates on the selected candidate. For
295 example, when viewing a list of files, one action could open it for
296 editing, one to view it, another to invoke a special function, and so
297 on. Custom actions can be added to this interface. The precise action
298 to call on the selected candidate can be delayed until after the
299 narrowing is completed. No need to exit the interface if unsure which
300 action to run. This delayed flexibility and customization of actions
301 extends usability of lists in Emacs.
303 - ~C-m~ or ~RET~ (=ivy-done=) ::
304 Calls the default action and exits the minibuffer.
306 - ~M-o~ (=ivy-dispatching-done=) ::
307 Presents all available valid actions from which to choose. When
308 there is only one action available, there is no difference
309 between ~M-o~ and ~C-m~.
311 - ~C-j~ (=ivy-alt-done=) ::
312 When completing file names, selects the current directory
313 candidate and starts a new completion session there. Otherwise,
314 it's the same as =ivy-done=.
316 - ~TAB~ (=ivy-partial-or-done=) ::
317 Attempts partial completion, extending current input as much as
318 possible. ~TAB TAB~ is the same as ~C-j~.
320 - ~C-M-j~ (=ivy-immediate-done=) ::
321 Exits with /the current input/ instead of /the current candidate/
322 (like other commands).
324 This is useful e.g. when you call =find-file= to create a new
325 file, but the desired name matches an existing file. In that
326 case, using ~C-j~ would select that existing file, which isn't
327 what you want - use this command instead.
329 - ~C-'~ (=ivy-avy=) ::
330 Uses avy to select one of the candidates on the current candidate
331 page. This can often be faster than multiple ~C-n~ or ~C-p~
332 keystrokes followed by ~C-m~.
334 *** Key bindings for multiple selections and actions, keep minibuffer open
336 :CUSTOM_ID: key-bindings-for-multiple-selections-and-actions-keep-minibuffer-open
339 For repeatedly applying multiple actions or acting on multiple
340 candidates, Ivy does not close the minibuffer between commands. It
341 keeps the minibuffer open for applying subsequent actions.
343 Adding an extra meta key to the normal key chord invokes the special
344 version of the regular commands that enables applying multiple
347 - ~C-M-m~ (=ivy-call=) ::
348 Is the non-exiting version of ~C-m~ (=ivy-done=).
350 Instead of closing the minibuffer, ~C-M-m~ allows selecting
351 another candidate or another action. For example, ~C-M-m~ on
352 functions list invokes =describe-function=. When combined with
353 ~C-n~, function descriptions can be invoked quickly in
356 - ~C-M-o~ (=ivy-dispatching-call=) ::
357 Is the non-exiting version of ~M-o~ (=ivy-dispatching-done=).
359 For example, during the =counsel-rhythmbox= completion, press
360 ~C-M-o e~ to en-queue the selected candidate, followed by ~C-n
361 C-m~ to play the next candidate - the current action reverts to
362 the default one after ~C-M-o~.
364 - ~C-M-n~ (=ivy-next-line-and-call=) ::
365 Combines ~C-n~ and ~C-M-m~. Applies an action and moves to next
368 Comes in handy when opening multiple files from
369 =counsel-find-file=, =counsel-git-grep=, =counsel-ag=, or
370 =counsel-locate= lists. Just hold ~C-M-n~ for rapid-fire default
371 action on each successive element of the list.
373 - ~C-M-p~ (=ivy-previous-line-and-call=) ::
374 Combines ~C-p~ and ~C-M-m~.
376 Similar to the above except it moves through the list in the
380 Recalls the state of the completion session just before its last exit.
382 Useful after an accidental ~C-m~ (=ivy-done=).
384 *** Key bindings that alter the minibuffer input
386 :CUSTOM_ID: key-bindings-that-alter-the-minibuffer-input
389 - ~M-n~ (=ivy-next-history-element=) ::
390 Cycles forward through the Ivy command history.
392 Ivy updates an internal history list after each action. When this
393 history list is empty, ~M-n~ inserts symbol (or URL) at point
396 - ~M-p~ (=ivy-previous-history-element=) ::
397 Cycles forward through the Ivy command history.
399 - ~M-i~ (=ivy-insert-current=) ::
400 Inserts the current candidate into the minibuffer.
402 Useful for copying and renaming files, for example: ~M-i~ to
403 insert the original file name string, edit it, and then ~C-m~ to
404 complete the renaming.
406 - ~M-j~ (=ivy-yank-word=) ::
407 Inserts the sub-word at point into the minibuffer.
409 This is similar to ~C-s C-w~ with =isearch=. Ivy reserves ~C-w~
412 - ~S-SPC~ (=ivy-restrict-to-matches=) ::
413 Deletes the current input, and resets the candidates list to the
414 currently restricted matches.
416 This is how Ivy provides narrowing in successive tiers.
418 - ~C-r~ (=ivy-reverse-i-search=) ::
419 Starts a recursive completion session through the command's
422 This works just like ~C-r~ at the bash command prompt, where the
423 completion candidates are the history items. Upon completion, the
424 selected candidate string is inserted into the minibuffer.
426 *** Other key bindings
428 :CUSTOM_ID: other-key-bindings
431 - ~M-w~ (=ivy-kill-ring-save=) ::
432 Copies selected candidates to the kill ring.
434 When the region is active, copies active region instead.
436 *** Hydra in the minibuffer
438 :CUSTOM_ID: hydra-in-the-minibuffer
441 - ~C-o~ (=hydra-ivy/body=) ::
442 Invokes the hydra menu with short key bindings.
444 Minibuffer editing is disabled when Hydra is active. Instead, you get
445 short aliases for the common commands:
447 | Short | Normal | Command name |
448 |-------+-----------+---------------------------|
449 | ~o~ | ~C-g~ | =keyboard-escape-quit= |
450 | ~j~ | ~C-n~ | =ivy-next-line= |
451 | ~k~ | ~C-p~ | =ivy-previous-line= |
452 | ~h~ | ~M-<~ | =ivy-beginning-of-buffer= |
453 | ~l~ | ~M->~ | =ivy-end-of-buffer= |
454 | ~d~ | ~C-m~ | =ivy-done= |
455 | ~f~ | ~C-j~ | =ivy-alt-done= |
456 | ~g~ | ~C-M-m~ | =ivy-call= |
457 | ~u~ | ~C-c C-o~ | =ivy-occur= |
459 Hydra reduces key strokes, for example: ~C-n C-n C-n C-n~ is ~C-o
462 Additionally, you get access to the folowing commands that are
465 - ~c~ (=ivy-toggle-calling=) ::
466 Toggle calling the action after each candidate change. This
467 effectively modifies ~j~ to ~jg~, ~k~ to ~kg~ etc.
469 - ~m~ (=ivy-toggle-fuzzy=) ::
470 Toggle the current regexp matcher.
472 - ~>~ (=ivy-minibuffer-grow=) ::
473 Increase =ivy-height= for the current minibuffer.
475 - ~<~ (=ivy-minibuffer-shrink=) ::
476 Decrease =ivy-height= for the current minibuffer.
478 - ~w~ (=ivy-prev-action=) ::
479 Select the previous action.
481 - ~s~ (=ivy-next-action=) ::
482 Select the next action.
484 - ~a~ (=ivy-read-action=) ::
485 Use a menu to select an action.
487 - ~C~ (=ivy-toggle-case-fold=) ::
488 Toggle case folding (matching both upper and lower case
489 characters with lower case input).
491 *** Saving the current completion session to a buffer
493 :CUSTOM_ID: saving-the-current-completion-session-to-a-buffer
496 - ~C-c C-o~ (=ivy-occur=) ::
497 Saves the current candidates to a new buffer and exits
500 The new buffer is read-only and has a few useful bindings defined.
502 - ~RET~ or ~j~ (=ivy-occur-press=) ::
503 Call the current action on the selected candidate.
505 - ~mouse-1~ (=ivy-occur-click=) ::
506 Call the current action on the selected candidate.
508 - ~j~ (=next-line=) ::
511 - ~k~ (=previous-line=) ::
512 Move to previous line.
514 - ~a~ (=ivy-occur-read-action=) ::
515 Read an action and make it current for this buffer.
517 - ~o~ (=ivy-occur-dispatch=) ::
518 Read an action and call it on the selected candidate.
520 - ~q~ (=quit-window=) ::
521 Bury the current buffer.
524 Ivy has no limit on the number of active buffers like these.
526 Ivy takes care of making these buffer names unique. It applies
527 descriptive names, for example: =*ivy-occur counsel-describe-variable
532 :CUSTOM_ID: completion-styles
535 Ivy's completion functions rely on the highly configurable regex
540 (setq ivy-re-builders-alist
541 '((t . ivy--regex-plus)))
544 The default =ivy--regex-plus= narrowing is always invoked unless
545 specified otherwise. For example, file name completion may have a
546 custom completion function:
548 (setq ivy-re-builders-alist
549 '((read-file-name-internal . ivy--regex-fuzzy)
550 (t . ivy--regex-plus)))
553 Ivy's flexibility extends to using different styles of completion
554 mechanics (regex-builders) for different types of lists. Despite this
555 flexibility, Ivy operates within a consistent and uniform interface.
556 The main regex-builders currently in Ivy are:
560 :CUSTOM_ID: ivy--regex-plus
563 =ivy--regex-plus= is Ivy's default completion method.
565 =ivy--regex-plus= matches by splitting the input by spaces and
566 rebuilding it into a regex.
568 As the search string is typed in Ivy's minibuffer, it is transformed
569 into proper regex syntax. If the string is ="for example"=, it is
573 "\\(for\\).*\\(example\\)"
576 which in regex terminology matches ="for"= followed by a wild card and
577 then ="example"=. Note how Ivy uses the space character to build wild
578 cards. For literal white space matching in Ivy, use an extra space: to
579 match one space type two spaces, to match two spaces type three
582 As Ivy transforms typed characters into regex strings, it provides an
583 intuitive feedback through font highlights.
585 Ivy supports regexp negation with ="!"=.
586 For example, ="define key ! ivy quit"= first selects everything
587 matching ="define.*key"=, then removes everything matching ="ivy"=,
588 and finally removes everything matching ="quit"=. What remains is the
589 final result set of the negation regexp.
591 Since Ivy treats minibuffer input as a regexp, the standard regexp
592 identifiers work: ="^"=, ="$"=, ="\b"= or ="[a-z]"=. The exceptions
593 are spaces, which translate to =".*"=, and ="!"= that signal the
594 beginning of a negation group.
596 ** ivy--regex-ignore-order
598 :CUSTOM_ID: ivy--regex-ignore-order
601 =ivy--regex-ignore-order= ignores the order of regexp tokens when
602 searching for matching candidates. For instance, the input
603 ="for example"= will match ="example test for"=.
607 :CUSTOM_ID: ivy--regex-fuzzy
610 =ivy--regex-fuzzy= splits each character with a wild card. Searching
611 for ="for"= returns all ="f.*o.*r"= matches, resulting in a large
612 number of hits. Yet some searches need these extra hits. Ivy sorts
613 such large lists using =flx= package's scoring mechanism, if it's
619 :CUSTOM_ID: variable-index