]> code.delx.au - gnu-emacs-elpa/blob - doc/ivy.texi
doc/ivy.texi: Re-export using adjusted texinfo exporter
[gnu-emacs-elpa] / doc / ivy.texi
1 \input texinfo @c -*- texinfo -*-
2 @c %**start of header
3 @setfilename ./ivy.info
4 @settitle Ivy User Manual
5 @documentencoding UTF-8
6 @documentlanguage en
7 @c %**end of header
8
9 @copying
10 @ifnottex
11 Ivy manual, version 0.7.0
12
13 Ivy is an interactive interface for completion in Emacs. Emacs uses
14 completion mechanism in a variety of contexts: code, menus, commands,
15 variables, functions, etc. Completion entails listing, sorting,
16 filtering, previewing, and applying actions on selected items. When
17 active, @code{ivy-mode} completes the selection process by narrowing
18 available choices while previewing in the minibuffer. Selecting the
19 final candidate is either through simple keyboard character inputs or
20 through powerful regular expressions. @end ifnottex
21
22 Copyright @copyright{} 2015 Free Software Foundation, Inc.
23
24 @quotation
25 Permission is granted to copy, distribute and/or modify this document
26 under the terms of the GNU Free Documentation License, Version 1.3 or
27 any later version published by the Free Software Foundation; with no
28 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
29 and with the Back-Cover Texts as in (a) below. A copy of the license
30 is included in the section entitled ``GNU Free Documentation License.''
31
32 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
33 modify this GNU manual.''
34 @end quotation
35 @end copying
36
37 @dircategory Emacs
38 @direntry
39 * Ivy: (ivy). Using Ivy for completion.
40 @end direntry
41
42 @finalout
43 @titlepage
44 @title Ivy User Manual
45 @author Oleh Krehel
46 @page
47 @vskip 0pt plus 1filll
48 @insertcopying
49 @end titlepage
50
51 @contents
52
53 @ifnottex
54 @node Top
55 @top Ivy User Manual
56 @insertcopying
57 @end ifnottex
58
59 @menu
60 * Introduction::
61 * Installation::
62 * Getting started::
63 * Key bindings::
64 * Completion styles::
65
66 @detailmenu
67 --- The Detailed Node Listing ---
68
69 Installation
70
71 * Installing from Emacs Package Manager::
72 * Installing from the Git repository::
73
74 Getting started
75
76 * Basic customization::
77
78 Key bindings
79
80 * Global key bindings::
81 * Minibuffer key bindings::
82
83 Minibuffer key bindings
84
85 * Key bindings for navigation::
86 * Key bindings for single selection, action, then exit minibuffer: Key bindings for single selection action then exit minibuffer.
87 * Key bindings for multiple selections and actions, keep minibuffer open: Key bindings for multiple selections and actions keep minibuffer open.
88 * Key bindings that alter minibuffer input::
89 * Other key bindings::
90 * Hydra in the minibuffer::
91 * Saving the current completion session to a buffer::
92 Completion styles
93
94 * ivy--regex-plus::
95 * ivy--regex-ignore-order::
96 * ivy--regex-fuzzy::
97 @end detailmenu
98 @end menu
99
100 @node Introduction
101 @chapter Introduction
102
103 Ivy is for quick and easy selection from a list. When Emacs prompts
104 for a string from a list of several possible choices, Ivy springs into
105 action to assist in narrowing and picking the right string from a vast
106 number of choices.
107
108 Ivy strives for minimalism, simplicity, customizability and
109 discoverability.
110
111 @subsubheading Minimalism
112 Uncluttered minibuffer is minimalism. Ivy shows the completion
113 defaults, the number of matches, and 10 candidate matches below the
114 input line. Customize @code{ivy-length} to adjust the number of candidate
115 matches displayed in the minibuffer.
116
117 @subsubheading Simplicity
118 Simplicity is about Ivy's behavior in the minibuffer. It is also about
119 the code interface to extend Ivy's functionality. The minibuffer area
120 behaves as close to @code{fundamental-mode} as possible. @kbd{SPC} inserts a
121 space, for example, instead of being bound to the more complex
122 @code{minibuffer-complete-word}. Ivy's code uses easy-to-examine global
123 variables; avoids needless complications with branch-introducing
124 custom macros.
125
126 @subsubheading Customizability
127 Customizability is about being able to use different methods and
128 interfaces of completion to tailor the selection process. For example,
129 adding a custom display function that points to a selected candidate
130 with @code{->}, instead of highlighting the selected candidate with the
131 @code{ivy-current-match} face. Or take the customization of actions, say
132 after the candidate function is selected. @kbd{RET} uses
133 @code{counsel-describe-function} to describe the function, whereas @kbd{M-o d}
134 jumps to that function's definition in the code. The @kbd{M-o} prefix can
135 be uniformly used with characters like @kbd{d} to group similar actions.
136
137 @subsubheading Discoverability
138 Ivy displays easily discoverable commands through the hydra facility.
139 @kbd{C-o} in the minibuffer displays a hydra menu. It opens up within an
140 expanded minibuffer area. Each menu item comes with short
141 documentation strings and highlighted one-key completions. So
142 discovering even seldom used keys is simply a matter of @kbd{C-o} in the
143 minibuffer while in the midst of the Ivy interaction. This
144 discoverability minimizes exiting Ivy interface for documentation
145 look-ups.
146
147 @node Installation
148 @chapter Installation
149
150 Install Ivy automatically through Emacs's package manager, or manually
151 from Ivy's development repository.
152 @menu
153 * Installing from Emacs Package Manager::
154 * Installing from the Git repository::
155 @end menu
156
157 @node Installing from Emacs Package Manager
158 @section Installing from Emacs Package Manager
159
160 @kbd{M-x} @code{package-install} @kbd{RET} @code{swiper} @kbd{RET}
161
162 Ivy is installed as part of @code{swiper} package. @code{swiper} is available
163 from two different package archives, GNU ELPA and MELPA. For the
164 latest stable version, use the GNU ELPA archives using the above M-x
165 command.
166
167 For current hourly builds, use the MELPA archives. See the code below
168 for adding MELPA to the list of package archives:
169
170
171 @lisp
172 (require 'package)
173 (add-to-list 'package-archives
174 '("melpa" . "http://melpa.org/packages/"))
175 @end lisp
176
177 After this do @kbd{M-x} @code{package-refresh-contents} @kbd{RET}, followed by
178 @kbd{M-x} @code{package-install} @kbd{RET} @code{swiper} @kbd{RET}.
179
180 For package manager details, see @ref{Packages,,,emacs,}.
181
182 @node Installing from the Git repository
183 @section Installing from the Git repository
184
185 Why install from Git?
186
187 @itemize
188 @item
189 No need to wait for MELPA's hourly builds
190 @item
191 Easy to revert to previous versions
192 @item
193 Contribute to Ivy's development; send patches; pull requests
194 @end itemize
195
196 @strong{Configuration steps}
197
198 First clone the Swiper repository:
199
200 @example
201 cd ~/git && git clone https://github.com/abo-abo/swiper
202 cd swiper && make compile
203 @end example
204
205 Then add this to Emacs init:
206
207 @lisp
208 (add-to-list 'load-path "~/git/swiper/")
209 (require 'ivy)
210 @end lisp
211
212 To update the code:
213
214 @example
215 git pull
216 make
217 @end example
218
219 @node Getting started
220 @chapter Getting started
221
222 First enable Ivy completion everywhere:
223
224
225 @lisp
226 (ivy-mode 1)
227 @end lisp
228
229 Note: @code{ivy-mode} can be toggled on and off with @kbd{M-x} @code{ivy-mode}.
230 @menu
231 * Basic customization::
232 @end menu
233
234 @node Basic customization
235 @section Basic customization
236
237 Here are some basic settings particularly useful for new Ivy
238 users:
239
240 @lisp
241 (setq ivy-use-virtual-buffers t)
242 (setq ivy-height 10)
243 (setq ivy-display-style 'fancy)
244 (setq ivy-count-format "(%d/%d) ")
245 @end lisp
246
247 For additional customizations, refer to @code{M-x describe-variable}
248 documentation.
249
250 @node Key bindings
251 @chapter Key bindings
252
253 @menu
254 * Global key bindings::
255 * Minibuffer key bindings::
256 @end menu
257
258 @node Global key bindings
259 @section Global key bindings
260
261 Recommended key bindings are:
262 @subsubheading Ivy-based interface to standard commands
263
264 @lisp
265 (global-set-key (kbd "C-s") 'swiper)
266 (global-set-key (kbd "M-x") 'counsel-M-x)
267 (global-set-key (kbd "C-x C-f") 'counsel-find-file)
268 (global-set-key (kbd "<f1> f") 'counsel-describe-function)
269 (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
270 (global-set-key (kbd "<f1> l") 'counsel-load-library)
271 (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
272 (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
273 @end lisp
274 @subsubheading Ivy-based interface to shell and system tools
275
276 @lisp
277 (global-set-key (kbd "C-c g") 'counsel-git)
278 (global-set-key (kbd "C-c j") 'counsel-git-grep)
279 (global-set-key (kbd "C-c k") 'counsel-ag)
280 (global-set-key (kbd "C-x l") 'counsel-locate)
281 (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
282 @end lisp
283 @subsubheading Ivy-resume and other commands
284 @code{ivy-resume} resumes the last Ivy-based completion.
285
286 @lisp
287 (global-set-key (kbd "C-c C-r") 'ivy-resume)
288 @end lisp
289
290 @node Minibuffer key bindings
291 @section Minibuffer key bindings
292
293 Ivy includes several minibuffer bindings, which are defined in the
294 @code{ivy-minibuffer-map} keymap variable. The most frequently used ones
295 are described here.
296
297 @code{swiper} or @code{counsel-M-x} add more through the @code{keymap} argument to
298 @code{ivy-read}. These keys, also active in the minibuffer, are described
299 under their respective commands.
300 @menu
301 * Key bindings for navigation::
302 * Key bindings for single selection, action, then exit minibuffer: Key bindings for single selection action then exit minibuffer.
303 * Key bindings for multiple selections and actions, keep minibuffer open: Key bindings for multiple selections and actions keep minibuffer open.
304 * Key bindings that alter minibuffer input::
305 * Other key bindings::
306 * Hydra in the minibuffer::
307 * Saving the current completion session to a buffer::
308 @end menu
309
310 @node Key bindings for navigation
311 @subsection Key bindings for navigation
312
313 @itemize
314 @item
315 @kbd{C-n} (@code{ivy-next-line}) selects the next candidate
316 @item
317 @kbd{C-p} (@code{ivy-previous-line}) selects the previous candidate
318 @item
319 @kbd{M-<} (@code{ivy-beginning-of-buffer}) selects the first candidate
320 @item
321 @kbd{M->} (@code{ivy-end-of-buffer}) selects the last candidate
322 @item
323 @kbd{C-v} (@code{ivy-scroll-up-command}) scrolls up by @code{ivy-height} lines
324 @item
325 @kbd{M-v} (@code{ivy-scroll-down-command}) scrolls down by @code{ivy-height} lines
326 @end itemize
327
328 @defopt ivy-wrap
329 This user option allows to get the wrap-around behavior for @kbd{C-n} and
330 @kbd{C-p}. When set to @code{t}, @code{ivy-next-line} and @code{ivy-previous-line} will
331 cycle past the last and the first candidates respectively.
332
333 This behavior is off by default.
334 @end defopt
335
336 @defopt ivy-height
337 Use this variable to adjust the minibuffer height, and therefore the
338 scroll size for @kbd{C-v} and @kbd{M-v}.
339 @end defopt
340
341 @node Key bindings for single selection action then exit minibuffer
342 @subsection Key bindings for single selection, action, then exit minibuffer
343
344 Ivy can offer several actions from which to choose which action to
345 run. This "calling an action" operates on the selected candidate. For
346 example, when viewing a list of files, one action could open it for
347 editing, one to view it, another to invoke a special function, and so
348 on. Custom actions can be added to this interface. The precise action
349 to call on the selected candidate can be delayed until after the
350 narrowing is completed. No need to exit the interface if unsure which
351 action to run. This delayed flexibility and customization of actions
352 extends usability of lists in Emacs.
353
354 @kbd{C-m} or @kbd{RET} (@code{ivy-done}) calls the default action and exits the
355 minibuffer.
356
357 @kbd{M-o} (@code{ivy-dispatching-done}) presents all available valid actions
358 from which to choose. When there is only one action available, there
359 is no difference between @kbd{M-o} and @kbd{C-m}.
360
361 @kbd{C-j} (@code{ivy-alt-done}) calls the alternate action, such as completing
362 a directory name in a file list whereas @kbd{C-m} will select that directory
363 and exit the minibuffer.
364
365 Exiting the minibuffer also closes the Ivy window (as specified by
366 @code{ivy-height}). This closing and exiting sequence is conveniently off
367 when applying multiple actions. Multiple actions and multiple
368 selections as covered in the next section of this manual.
369
370 @kbd{TAB} (@code{ivy-partial-or-done}) attempts partial completion, extending
371 current input as much as possible.
372
373 @kbd{TAB TAB} is the same as @kbd{C-j}.
374
375 @kbd{C-M-j} (@code{ivy-immediate-done}) is useful when there is no match for
376 the given input. Or there is an incorrect partial match. @kbd{C-M-j} with
377 @code{find-file} lists ignores the partial match and instead takes the
378 current input to create a new directory with @code{dired-create-directory}.
379
380 @code{ivy-immediate-done} illustrates how Ivy distinguishes between calling
381 an action on the @emph{currently selected} candidate and calling an action
382 on the @emph{current input}.
383
384 Invoking avy completion with @kbd{C-'} (@code{ivy-avy}).
385 @kbd{C-`} uses avy's visible jump mechanism, which can further reduce
386 Ivy's line-by-line scrolling that requires multiple @kbd{C-n} or @kbd{C-p}
387 keystrokes.
388
389 @node Key bindings for multiple selections and actions keep minibuffer open
390 @subsection Key bindings for multiple selections and actions, keep minibuffer open
391
392 For repeatedly applying multiple actions or acting on multiple
393 candidates, Ivy does not close the minibuffer between commands. It
394 keeps the minibuffer open for applying subsequent actions.
395
396 Adding an extra meta key to the normal key chord invokes the special
397 version of the regular commands that enables applying multiple
398 actions.
399
400 @kbd{C-M-m} (@code{ivy-call}) is the non-exiting version of the default action,
401 @kbd{C-m} (@code{ivy-done}). Instead of closing the minibuffer, @kbd{C-M-m} allows
402 selecting another candidate or another action. For example, @kbd{C-M-m} on
403 functions list invokes @code{describe-function}. When combined with @kbd{C-n},
404 function descriptions can be invoked quickly in succession.
405
406 @kbd{RET} exits the minibuffer.
407
408 @code{ivy-resume} recalls the state of the completion session just before
409 its last exit. Useful after an accidental @kbd{C-m} (@code{ivy-done}).
410
411 @kbd{C-M-o} (@code{ivy-dispatching-call}) is a non-exiting version of @kbd{M-o}
412 (@code{ivy-dispatching-done}) that can accumulate candidates into a queue.
413 For example, for playback in @code{counsel-rhythmbox}, @kbd{C-M-o e} en-queues
414 the selected candidate, and @kbd{C-n C-m} plays the next one in the queue.
415
416 @kbd{C-M-n} (@code{ivy-next-line-and-call}) combines @kbd{C-n} and @kbd{C-M-m}. Applies
417 an action and moves to next line. Comes in handy when opening multiple
418 files from @code{counsel-find-file}, @code{counsel-git-grep}, @code{counsel-ag}, or
419 @code{counsel-locate} lists. Just hold @kbd{C-M-n} for rapid-fire default
420 action on each successive element of the list.
421
422 @kbd{C-M-p} (@code{ivy-previous-line-and-call}) combines @kbd{C-p} and @kbd{C-M-m}. Is
423 the same as above except that it moves through the list in the other
424 direction.
425
426 @node Key bindings that alter minibuffer input
427 @subsection Key bindings that alter minibuffer input
428
429 @kbd{M-n} (@code{ivy-next-history-element}) and @kbd{M-p}
430 (@code{ivy-previous-history-element}) cycle through the Ivy command
431 history. Ivy updates an internal history list after each action. When
432 this history list is empty, @kbd{M-n} inserts symbol (or URL) at point
433 into the minibuffer.
434
435 @kbd{M-i} (@code{ivy-insert-current}) inserts the current candidate into the
436 minibuffer. Useful for copying and renaming files, for example: @kbd{M-i}
437 to insert the original file name string, edit it, and then @kbd{C-m} to
438 complete the renaming.
439
440 @kbd{M-j} (@code{ivy-yank-word}) inserts sub-word at point into minibuffer. This
441 is similar to @kbd{C-s C-w} with @code{isearch}. Ivy reserves @kbd{C-w} for
442 @code{kill-region}.
443
444 @kbd{S-SPC} (@code{ivy-restrict-to-matches}) deletes the current input, and
445 resets the candidates list to the currently restricted matches. This
446 is how Ivy provides narrowing in successive tiers.
447
448 @kbd{C-r} (@code{ivy-reverse-i-search}) works just like @kbd{C-r} at bash command
449 prompt, where the completion candidates are the history items. Upon
450 completion, the selected candidate string is inserted into the
451 minibuffer.
452
453 @node Other key bindings
454 @subsection Other key bindings
455
456 @kbd{M-w} (@code{ivy-kill-ring-save}) copies selected candidates to the kill
457 ring; when the region is active, copies active region.
458
459 @node Hydra in the minibuffer
460 @subsection Hydra in the minibuffer
461
462 @kbd{C-o} (@code{hydra-ivy/body}) invokes Hydra menus with key shortcuts.
463
464 @kbd{C-o} or @kbd{i} resumes editing.
465
466 Hydra reduces key strokes, for example: @kbd{C-n C-n C-n C-n} is @kbd{C-o
467 jjjj} in Hydra. Hydra has other benefits besides certain shorter key
468 bindings:
469 @itemize
470 @item
471 @kbd{<} and @kbd{>} to adjust height of minibuffer,
472 @item
473 describes the current completion state, such as case folding and the
474 current action.
475 @end itemize
476
477 Minibuffer editing is disabled when Hydra is active.
478
479 @node Saving the current completion session to a buffer
480 @subsection Saving the current completion session to a buffer
481
482 @kbd{C-c C-o} (@code{ivy-occur}) saves the current candidates to a new buffer;
483 the list is active in the new buffer.
484
485 @kbd{RET} or @kbd{mouse-1} in the new buffer calls the appropriate action on
486 the selected candidate.
487
488 Ivy has no limit on the number of active buffers like these.
489
490 Ivy takes care of making these buffer names unique. It applies
491 descriptive names, for example: @code{*ivy-occur counsel-describe-variable
492 "function$*}.
493
494 @node Completion styles
495 @chapter Completion styles
496
497 Ivy's completion functions rely on the highly configurable regex
498 builder.
499
500 The default is:
501
502 @lisp
503 (setq ivy-re-builders-alist
504 '((t . ivy--regex-plus)))
505 @end lisp
506
507 The default @code{ivy--regex-plus} narrowing is always invoked unless
508 specified otherwise. For example, file name completion may have a
509 custom completion function:
510
511 @lisp
512 (setq ivy-re-builders-alist
513 '((read-file-name-internal . ivy--regex-fuzzy)
514 (t . ivy--regex-plus)))
515 @end lisp
516
517 Ivy's flexibility extends to using different styles of completion
518 mechanics (regex-builders) for different types of lists. Despite this
519 flexibility, Ivy operates within a consistent and uniform interface.
520 The main regex-builders currently in Ivy are:
521 @menu
522 * ivy--regex-plus::
523 * ivy--regex-ignore-order::
524 * ivy--regex-fuzzy::
525 @end menu
526
527 @node ivy--regex-plus
528 @section ivy--regex-plus
529
530 @code{ivy--regex-plus} is Ivy's default completion method.
531
532 @code{ivy--regex-plus} matches by splitting the input by spaces and
533 rebuilding it into a regex.
534
535 As the search string is typed in Ivy's minibuffer, it is transformed
536 into proper regex syntax. If the string is "for example", it is
537 transformed into
538
539 @verbatim
540 "\\(for\\).*\\(example\\)"
541 @end verbatim
542
543 which in regex terminology matches "for" followed by a wild card and
544 then "example". Note how Ivy uses the space character to build
545 wild cards. For literal white space matching in Ivy, use an extra space:
546 to match one space type two spaces, to match two spaces type three
547 spaces, and so on.
548
549 As Ivy transforms typed characters into regex strings, it provides an
550 intuitive feedback through font highlights.
551
552 Ivy supports regexp negation with "!". For example, "define key ! ivy
553 quit" first selects everything matching "define.*key", then removes
554 everything matching "ivy", and finally removes everything matching
555 "quit". What remains is the final result set of the negation regexp.
556
557 @verbatim
558 Standard regexp identifiers work:
559
560 "^", "$", "\b" or "[a-z]"
561 @end verbatim
562
563 Since Ivy treats minibuffer input as a regexp, standard regexp
564 identifiers work as usual. The exceptions are spaces, which
565 translate to ".*", and "!" that signal the beginning of a negation
566 group.
567
568 @node ivy--regex-ignore-order
569 @section ivy--regex-ignore-order
570
571 @code{ivy--regex-ignore-order} ignores the order of regexp tokens when
572 searching for matching candidates. For instance, the input "for
573 example" will match "example test for". Otherwise @code{ivy--regex-plus}
574 normal behavior is to honor the order of regexp tokens.
575
576 @node ivy--regex-fuzzy
577 @section ivy--regex-fuzzy
578
579 @code{ivy--regex-fuzzy} splits each character with a wild card. Searching
580 for "for" returns all "f.*o.*r" matches, resulting in a large number
581 of hits. Yet some searches need these extra hits. Ivy sorts such
582 large lists using @code{flx} package's scoring mechanism, if it's
583 installed.
584
585 @bye