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