To highlight a section without introducing a new subheading use
definition lists. The definition list “owns” the subsequent text if
the text is indented by 5 spaces. Use M-q to indent the paragraphs.
Start new paragraphs with 5 spaces indented. To separate definition
lists from regular lists, use two newlines.
A typical definition list:
- ~C-M-j~ (=ivy-immediate-done=) ::
The code and kbd part is recognized and added as @vindex and
@kindex respectively.
Use definition lists to declare a @defopt section for defcustom
or defvar. For proper Texinfo export, use this form:
User Option =ivy-wrap= ::
Set CUSTOM_ID property to name each heading. For example, worf’s
C-u L. This will result in consistent HTML node names.
Keep one empty line before each source block for proper Texinfo exports.
ivy.texi is generated from ivy.org. To update the .texi file, eval
ivy-ox.el then C-c C-e i t in the ivy.org buffer.
Ivy manual, version 0.15.1
Ivy is an interactive interface for completion in Emacs. Emacs uses
completion mechanism in a variety of contexts: code, menus, commands,
variables, functions, etc. Completion entails listing, sorting,
filtering, previewing, and applying actions on selected items. When
active, ivy-mode completes the selection process by narrowing
available choices while previewing in the minibuffer. Selecting the
final candidate is either through simple keyboard character inputs or
through powerful regular expressions.
Copyright (C) 2015–2026 Free Software Foundation, Inc.
This manual source Ivy is for quick and easy selection from a list. When Emacs prompts for a string from a list of several possible choices, Ivy springs into action to assist in narrowing and picking the right string from a vast number of choices.Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.
Ivy strives for minimalism, simplicity, customizability and discoverability.
- Minimalism
-
Uncluttered minibuffer is minimalism. Ivy shows the completion
defaults, the number of matches, and 10 candidate matches below
the input line. Customize
ivy-heightto adjust the number of candidate matches displayed in the minibuffer. - Simplicity
-
Simplicity is about Ivy’s behavior in the minibuffer. It is also
about the code interface to extend Ivy’s functionality. The
minibuffer area behaves as close to
fundamental-modeas possible.SPCinserts a space, for example, instead of being bound to the more complexminibuffer-complete-word. Ivy’s code uses easy-to-examine global variables; avoids needless complications with branch-introducing custom macros. - Customizability
-
Customizability is about being able to use different methods and
interfaces of completion to tailor the selection process. For
example, adding a custom display function that points to a
selected candidate with
>, instead of highlighting the selected candidate with theivy-current-matchface (seeivy-format-functions-alist). Or take the customization of actions, say after the candidate function is selected.RETusescounsel-describe-functionto describe the function, whereasM-o djumps to that function’s definition in the code. TheM-oprefix can be uniformly used with characters likedto group similar actions. - Discoverability
-
Ivy displays easily discoverable commands through the Hydra
facility.
C-oin the minibuffer displays a hydra menu. It opens up within an expanded minibuffer area. Each menu item comes with short documentation strings and highlighted one-key completions. So discovering even seldom used keys is simply a matter ofC-oin the minibuffer while in the midst of the Ivy interaction. This discoverability minimizes exiting Ivy interface for documentation look-ups.
Install Ivy automatically through Emacs’s package manager, or manually from Ivy’s development repository.
Emacs 24.5 is the oldest version to run Ivy.
M-x package-install RET counsel RET
Ivy is installed alongside the counsel package, which is available
from two different package archives, GNU ELPA and MELPA. For the
latest stable version, use the GNU ELPA archive. For the latest
development snapshot, use the GNU-devel ELPA archive.
Ivy is split into three packages: ivy, swiper and counsel; by
installing counsel, the other two are brought in as dependencies.
If you are not interested in the extra functionality provided by
swiper and counsel, you can install only ivy.
See the code below for adding GNU-devel ELPA to your list of package archives:
(require 'package)
(add-to-list 'package-archives
'("gnu-devel" . "https://elpa.gnu.org/devel/"))After this do M-x package-refresh-contents RET, followed by M-x
package-install RET counsel RET.
For package manager details, see info:emacs#Packages.
- Why install from Git?
-
- No need to wait for GNU ELPA / MELPA builds.
- Easy to revert to previous versions.
- Contribute to Ivy’s development; send patches; pull requests.
- Configuration steps
-
First clone the Swiper repository with:
cd ~/git && git clone 'https://github.com/abo-abo/swiper.git' cd swiper && make deps all
Second, add these lines to the Emacs init file:
(add-to-list 'load-path "~/git/swiper") (require 'ivy)
Then, update the code with:
git pull make
(ivy-mode 1)Note: ivy-mode can be toggled on and off with M-x ivy-mode.
(setopt ivy-use-virtual-buffers t)
(setopt ivy-count-format "(%d/%d) ")If you want, you can go without any customizations at all. The settings above give the most bang for the buck in terms of customization. So users that typically don’t like customizing a lot are advised to look at these settings first.
For more advanced customizations, refer to M-x describe-variable
documentation.
- Ivy-based interface to standard commands
-
(keymap-global-set "C-s" #'swiper-isearch) (keymap-global-set "M-x" #'counsel-M-x) (keymap-global-set "C-x C-f" #'counsel-find-file) (keymap-global-set "M-y" #'counsel-yank-pop) (keymap-global-set "<f1> f" #'counsel-describe-function) (keymap-global-set "<f1> v" #'counsel-describe-variable) (keymap-global-set "<f1> o" #'counsel-describe-symbol) (keymap-global-set "<f1> l" #'counsel-find-library) (keymap-global-set "<f2> i" #'counsel-info-lookup-symbol) (keymap-global-set "<f2> u" #'counsel-unicode-char) (keymap-global-set "<f2> j" #'counsel-set-variable) (keymap-global-set "C-x b" #'ivy-switch-buffer) (keymap-global-set "C-c v" #'ivy-push-view) (keymap-global-set "C-c V" #'ivy-pop-view)
- Ivy-based interface to shell and system tools
-
(keymap-global-set "C-c c" #'counsel-compile) (keymap-global-set "C-c g" #'counsel-git) (keymap-global-set "C-c j" #'counsel-git-grep) (keymap-global-set "C-c L" #'counsel-git-log) (keymap-global-set "C-c k" #'counsel-rg) (keymap-global-set "C-c m" #'counsel-linux-app) (keymap-global-set "C-c n" #'counsel-fzf) (keymap-global-set "C-x l" #'counsel-locate) (keymap-global-set "C-c J" #'counsel-file-jump) (keymap-global-set "C-S-o" #'counsel-rhythmbox) (keymap-global-set "C-c w" #'counsel-wmctrl)
- Ivy-resume and other commands
-
ivy-resumeresumes the last Ivy-based completion.(keymap-global-set "C-c C-r" #'ivy-resume) (keymap-global-set "C-c b" #'counsel-bookmark) (keymap-global-set "C-c d" #'counsel-descbinds) (keymap-global-set "C-c o" #'counsel-outline) (keymap-global-set "C-c t" #'counsel-load-theme) (keymap-global-set "C-c F" #'counsel-org-file)
You can also enable counsel-mode to make some global key binding remapping for you.
Ivy includes several minibuffer bindings, which are defined in the
ivy-minibuffer-map keymap variable. The most frequently used ones
are described here.
swiper or counsel-M-x add more key bindings through the keymap
argument to ivy-read. These keys, also active in the minibuffer,
are described under their respective commands.
A key feature of ivy-minibuffer-map is its full editing capability
where the familiar C-a, C-f, M-d, M-DEL, M-b, M-w, C-k,
C-y key bindings work the same as in fundamental-mode.
C-n(ivy-next-line) selects the next candidateC-p(ivy-previous-line) selects the previous candidateM-<(ivy-beginning-of-buffer) selects the first candidateM->(ivy-end-of-buffer) selects the last candidateC-v(ivy-scroll-up-command) scrolls up byivy-heightlinesM-v(ivy-scroll-down-command) scrolls down byivy-heightlines
- User Option
ivy-wrap -
Specifies the wrap-around behavior for
C-nandC-p. Whenivy-wrapis set tot,ivy-next-lineandivy-previous-linewill cycle past the last and the first candidates respectively.Wrap-around behavior is off by default.
- User Option
ivy-height -
Use this option to adjust the minibuffer height, which also
affects scroll size when using
C-vandM-vkey bindings.ivy-heightis 10 lines by default.
Ivy can offer several actions from which to choose which action to run. This “calling an action” operates on the selected candidate. For example, when viewing a list of files, one action could open it for editing, one to view it, another to invoke a special function, and so on. Custom actions can be added to this interface. The precise action to call on the selected candidate can be delayed until after the narrowing is completed. No need to exit the interface if unsure which action to run. This delayed flexibility and customization of actions extends usability of lists in Emacs.
C-morRET(ivy-done)- Calls the default action and then exits the minibuffer.
M-o(ivy-dispatching-done)-
Presents valid actions from which to choose. When only one action
is available, there is no difference between
M-oandC-m. C-j(ivy-alt-done)-
When completing file names, selects the current directory
candidate and starts a new completion session there. Otherwise,
it is the same as
ivy-done. TAB(ivy-partial-or-done)-
Attempts partial completion, extending current input as much as
possible.
TAB TABis the same asC-j(ivy-alt-done).Example ERT test:
(should (equal (ivy-with '(progn (ivy-read "Test: " '("can do" "can't, sorry" "other")) ivy-text) "c <tab>") "can"))
C-M-j(ivy-immediate-done)-
Exits with the current input instead of the current candidate
(like other commands).
This is useful e.g. when you call
find-fileto create a new file, but the desired name matches an existing file. In that case, usingC-jwould select that existing file, which isn’t what you want — use this command instead. C-'(ivy-avy)-
Uses Avy to select one of the candidates on the current candidate
page. This can often be faster than multiple
C-norC-pkeystrokes followed byC-m.
For repeatedly applying multiple actions or acting on multiple candidates, Ivy does not close the minibuffer between commands. It keeps the minibuffer open for applying subsequent actions.
Adding an extra meta key to the normal key chord invokes the special version of the regular commands that enables applying multiple actions.
Note that these operations are supported only by completion sessions
that use the ivy-read API, rather than the built-in
completing-read.
C-M-m(ivy-call)-
Is the non-exiting version of
C-m(ivy-done).Instead of closing the minibuffer,
C-M-mallows selecting another candidate or another action. For example,C-M-mon functions list invokesdescribe-function. When combined withC-n, function descriptions can be invoked quickly in succession. C-M-o(ivy-dispatching-call)-
Is the non-exiting version of
M-o(ivy-dispatching-done).For example, during the
counsel-rhythmboxcompletion, pressC-M-o eto en-queue the selected candidate, followed byC-n C-mto play the next candidate — the current action reverts to the default one afterC-M-o. C-M-n(ivy-next-line-and-call)-
Combines
C-nandC-M-m. Moves to next line and applies an action.Comes in handy when opening multiple files from
counsel-find-file,counsel-git-grep,counsel-ag,counsel-rg, orcounsel-locatelists. Just holdC-M-nfor rapid-fire default action on each successive element of the list. C-M-p(ivy-previous-line-and-call)-
Combines
C-pandC-M-m.Similar to the above except it moves through the list in the other direction.
ivy-resume-
Recalls the state of the completion session just before its last
exit.
Useful after an accidental
C-m(ivy-done). Use it withuniversal-argumentto resume any previous session.
M-n(ivy-next-history-element)-
Cycles forward through the Ivy command history.
Ivy updates an internal history list after each action. When this history list is empty,
M-ninserts the symbol (or URL) at point into the minibuffer. M-p(ivy-previous-history-element)- Cycles backwards through the Ivy command history.
M-i(ivy-insert-current)-
Inserts the current candidate into the minibuffer.
Useful for copying and renaming files, for example:
M-ito insert the original file name string, edit it, and thenC-mto complete the renaming. M-j(ivy-yank-word)-
Inserts the sub-word at point into the minibuffer.
This is similar to
C-s C-wwithisearch. Ivy reservesC-wforkill-region. See alsoivy-yank-symbolandivy-yank-char. S-SPC(ivy-restrict-to-matches)-
Deletes the current input, and resets the candidates list to the
currently restricted matches.
This is how Ivy provides narrowing in successive tiers.
C-r(ivy-reverse-i-search)-
Starts a recursive completion session through the command’s
history.
This works just like
C-rat the bash command prompt, where the completion candidates are the history items. Upon completion, the selected candidate string is inserted into the minibuffer.
M-w(ivy-kill-ring-save)-
Copies selected candidates to the kill ring.
Copies the region if the region is active.
C-o(hydra-ivy/body)- Invokes the hydra menu with short key bindings.
When Hydra is active, minibuffer editing is disabled and menus display short aliases:
| Short | Normal | Command name |
|---|---|---|
o | C-g | keyboard-escape-quit |
j | C-n | ivy-next-line |
k | C-p | ivy-previous-line |
h | M-< | ivy-beginning-of-buffer |
l | M-> | ivy-end-of-buffer |
d | C-m | ivy-done |
f | C-j | ivy-alt-done |
g | C-M-m | ivy-call |
u | C-c C-o | ivy-occur |
Hydra reduces key strokes, for example: C-n C-n C-n C-n is C-o
jjjj in Hydra.
Hydra menu offers these additional bindings:
c(ivy-toggle-calling)-
Toggle calling the action after each candidate change. It
modifies
jtojg,ktokgetc. M(ivy-rotate-preferred-builders)- Rotate the current regexp matcher.
>(ivy-minibuffer-grow)-
Increase
ivy-heightfor the current minibuffer. <(ivy-minibuffer-shrink)-
Decrease
ivy-heightfor the current minibuffer. w(ivy-prev-action)- Select the previous action.
s(ivy-next-action)- Select the next action.
a(ivy-read-action)- Use a menu to select an action.
C(ivy-toggle-case-fold)- Toggle case folding (match both upper and lower case characters for lower case input).
Hydra menu also offers bindings for marking multiple candidates:
| Key | Command name |
|---|---|
m | ivy-mark |
u | ivy-unmark |
DEL | ivy-unmark-backward |
t | ivy-toggle-marks |
The action is called on each marked candidate one by one.
C-c C-o(ivy-occur)- Saves the current candidates to a new buffer and exits completion.
The new buffer is read-only and has a few useful bindings defined.
RETorf(ivy-occur-press)- Call the current action on the selected candidate.
mouse-1(ivy-occur-click)- Call the current action on the selected candidate.
j(next-line)- Move to next line.
k(previous-line)- Move to previous line.
a(ivy-occur-read-action)- Read an action and make it current for this buffer.
o(ivy-occur-dispatch)- Read an action and call it on the selected candidate.
q(quit-window)- Bury the current buffer.
Ivy has no limit on the number of active buffers like these.
Ivy takes care of naming buffers uniquely by constructing descriptive
names. For example: *ivy-occur counsel-describe-variable
"function$*.
Ivy’s completion functions rely on a regexp builder — a function that
transforms a string input into a string regexp. All current candidates
simply have to match this regexp. Each collection can be assigned its
own regexp builder by customizing ivy-re-builders-alist.
The keys of this alist are collection names, and the values are one of the following:
ivy--regexivy--regex-plusivy--regex-ignore-orderivy--regex-fuzzyregexp-quote
A catch-all key, t, applies to all collections that don’t have their
own key.
The default is:
(setq ivy-re-builders-alist
'((t . ivy--regex-plus)))This example shows a custom regexp builder assigned to file name completion:
(setq ivy-re-builders-alist
'((read-file-name-internal . ivy--regex-fuzzy)
(t . ivy--regex-plus)))Here, read-file-name-internal is a function that is passed as the
second argument to completing-read for file name completion.
The regexp builder resolves as follows (in order of priority):
re-builderargument passed toivy-read.collectionargument passed toivy-readis a function and has an entry inivy-re-builders-alist.callerargument passed toivy-readhas an entry inivy-re-builders-alist.this-commandhas an entry inivy-re-builders-alist.thas an entry inivy-re-builders-alist.ivy--regex.
ivy--regex-plus is Ivy’s default completion method.
ivy--regex-plus matches by splitting the input by spaces and
rebuilding it into a regexp.
As the search string is typed in Ivy’s minibuffer, it is transformed
into valid regexp syntax. If the string is "for example", it is
transformed into:
"\\(for\\).*\\(example\\)"which in regexp terminology matches "for" followed by a wild card and
then "example". Note how Ivy uses the space character to build wild
cards. To match a literal white space, use an extra space. So to match
one space type two spaces, to match two spaces type three spaces, and
so on.
As Ivy transforms typed characters into regexp strings, it provides an intuitive feedback through font highlights.
Ivy supports regexp negation with "!".
For example, "define key ! ivy quit" first selects everything
matching "define.*key", then removes everything matching "ivy",
and finally removes everything matching "quit". What remains is the
final result set of the negation regexp.
Since Ivy treats minibuffer input as a regexp, the standard regexp
identifiers work: "^", "$", "\b" or "[a-z]". The exceptions
are spaces, which translate to ".*", and "!", that signals the
beginning of a negation group.
ivy--regex-ignore-order ignores the order of regexp tokens when
searching for matching candidates. For instance, the input
"for example" will match "example test for".
ivy--regex-fuzzy splits each character with a wild card. Searching
for "for" returns all "f.*o.*r" matches, resulting in a large
number of hits. Yet some searches need these extra hits. Ivy sorts
such large lists using flx package’s scoring mechanism, if it’s
installed.
C-o m toggles the current regexp builder.
ivy-current-match- Highlights the currently selected candidate.
ivy-minibuffer-match-face-1- Highlights the background of the match.
ivy-minibuffer-match-face-2- Highlights the first (modulo 3) matched group.
ivy-minibuffer-match-face-3- Highlights the second (modulo 3) matched group.
ivy-minibuffer-match-face-4- Highlights the third (modulo 3) matched group.
ivy-confirm-face-
Highlights the “(confirm)” part of the prompt.
When
confirm-nonexistent-file-or-bufferis set tot, confirming non-existent files inivy-moderequires an additionalRET.The confirmation prompt will use this face.
For example:
(setopt confirm-nonexistent-file-or-buffer t)Then call
find-file, enter “eldorado” and pressRET— the prompt will have “(confirm)” appended. PressRETonce more to confirm, or any key to continue the completion. ivy-match-required-face-
Highlights the “(match required)” part of the prompt.
When completions have to match available candidates and cannot take random input, the “(match required)” prompt signals this constraint.
For example, call
describe-variable, enter “waldo” and pressRET— “(match required)” is indicated. Press any key for the indication to disappear. ivy-subdir- Highlights directories when completing file names.
ivy-remote- Highlights remote files when completing file names.
ivy-virtual-
Highlights virtual buffers when completing buffer names.
Virtual buffers correspond to bookmarks and the recent files list from
recentf.Enable virtual buffers with:
(setopt ivy-use-virtual-buffers t) ivy-modified-buffer- Highlights modified buffers when switching buffer.
ivy-modified-outside-buffer-
Highlights buffers modified outside Emacs when switching buffer.
This takes precedence over
ivy-modified-buffer.
- User Option
ivy-count-format -
A string controlling how to display the number of candidates and
the current candidate, if one exists.
The number of matching candidates by default is shown as a right-padded integer value.
To disable showing the number of candidates:
(setopt ivy-count-format "")To also display the current candidate:
(setopt ivy-count-format "(%d/%d) ")The
format-style switches this variable uses are described in theformatdocumentation. - User Option
ivy-display-style -
Controls how to highlight candidates in the minibuffer.
The default setting is
fancy.Set
ivy-display-styletonilfor a plain minibuffer. - User Option
ivy-on-del-error-function -
Specifies what to do when
DEL(ivy-backward-delete-char) fails.This is usually the case when there is no text left to delete, i.e., when
DELis typed at the beginning of the minibuffer.The default behavior is to quit the completion after
DEL— a handy key to invoke after mistakenly triggering a completion.Another common option is
ignore, which does nothing.
- Window context when calling an action
-
Currently, the action is executed in the minibuffer window
context. This means e.g. that if you call
insertthe text will be inserted into the minibuffer.If you want to execute the action in the initial window from which the completion started, use the
with-ivy-windowwrapper macro.(defun ivy-insert-action (x) (with-ivy-window (insert x)))
C-m(ivy-done) calls the current action.M-o(ivy-dispatching-done) presents available actions for selection, calls the selected one, and then exits.C-M-o(ivy-dispatching-call) presents available actions for selection, calls the selected one, and then does not exit.
Usually, the command has only one default action. The convention is to
use single letters when selecting a command, and the letter o is
designated for the default command. This way, M-o o should always be
equivalent to C-m.
ivy-read was called.
The second action copies the current candidate to the kill ring.
(defun ivy-yank-action (x)
(kill-new x))
(defun ivy-copy-to-buffer-action (x)
(with-ivy-window
(insert x)))
(ivy-set-actions
t
'(("i" ivy-copy-to-buffer-action "insert")
("y" ivy-yank-action "yank")))Then in any completion session, M-o y invokes ivy-yank-action, and
M-o i invokes ivy-copy-to-buffer-action.
ivy-set-actions modifies the internal dictionary with new
data, set the extra actions list to nil by assigning a nil value to
the t key as follows:
(ivy-set-actions t nil)(ivy-set-actions
'swiper
'(("i" ivy-copy-to-buffer-action "insert")
("y" ivy-yank-action "yank")))(defun my-action-1 (x)
(message "action-1: %s" x))
(defun my-action-2 (x)
(message "action-2: %s" x))
(defun my-action-3 (x)
(message "action-3: %s" x))
(defun my-command-with-3-actions ()
(interactive)
(ivy-read "test: " '("foo" "bar" "baz")
:action '(1
("o" my-action-1 "action 1")
("j" my-action-2 "action 2")
("k" my-action-3 "action 3"))))The number 1 above is the index of the default action. Each action has its own string description for easy selection.
To examine each action with each candidate in a key-efficient way, try:- Call
my-command-with-3-actions - Press
C-c C-oto close the completion window and move to anivy-occurbuffer - Press
kkkto move to the first candidate, since the point is most likely at the end of the buffer - Press
ooto call the first action - Press
ojandokto call the second and third actions - Press
jto move to the next candidate - Press
oo,oj,ok - Press
jto move to the next candidate - and so on…
org-mode-
org-modeversions 8.3.3 or later obeycompleting-read-function(whichivy-modesets). Try refiling headings with similar names to appreciateivy-mode. magit- Uses Ivy by default if Ivy is installed.
find-file-in-project- Uses Ivy by default if Ivy is installed.
projectile-
Projectile requires this setting for Ivy completion:
(setopt projectile-completion-system 'ivy) helm-make-
Helm-make requires this setting for Ivy completion.
(setopt helm-make-completion-method 'ivy) - automatically integrated packages
-
Ivy reuses the following packages if they are installed:
avy,amxorsmex,flx, andwgrep.
C-j(ivy-alt-done)-
On a directory, restart completion from that directory.
On a file or
./, exit completion with the selected candidate. DEL(ivy-backward-delete-char)- Restart the completion in the parent directory if current input is empty.
//(self-insert-command)- Switch to the root directory.
- ~~~ (
self-insert-command) - Switch to the home directory.
/(self-insert-command)- If the current input matches an existing directory name exactly, switch the completion to that directory.
C-M-y(ivy-insert-current-full)- Insert the current full file name, in case you want to edit part of it.
M-r(ivy-toggle-regexp-quote)-
Toggle between input as regexp or plain text.
This can help with matching file names literally, since they often include
.in their name, which is a special character in regexp mode. - User Option
ivy-extra-directories -
Decide whether you want to see
../and./during file name completion.Reason to remove:
../is the same asDEL.Reason not to remove: navigate anywhere with only
C-n,C-pandC-j.Likewise,
./can be removed. - History
-
File history works the same with
M-p,M-n, andC-r, but uses a custom code for file name completion that cycles through files previously opened. It also works with TRAMP files.
- ~~~ (tilde)
-
Move to the home directory. Either the local or the remote one,
depending on the current directory. The boolean option
ivy-magic-tildedecides whether the binding to do this is ~~~ or ~~/~. //(double slash)-
Move to the root directory. Either the local or the remote one,
depending on the current directory. Here, you can also select a
TRAMP connection method, such as
sshorscpx. / C-j- Move to the local root directory.
- ~~~~
- Move to the local home directory.
From any directory, with the empty input, inserting /ssh: and pressing
C-j (or RET, which is the same thing) completes host and user
names.
For /ssh:user@ input, completes the domain name.
C-i works in a similar way to the default completion.
You can also get sudo access for the current directory by inputting
/sudo:: RET. Using /sudo: (i.e. single colon instead of double) will
result in a completion session for the desired user.
Multi-hopping is possible, although a bit complex.
- Example : connect to a remote host
cloudand open a file withsudothere -
C-x C-f/ssh:cloud|sudo:root:/.
- User Option
ivy-use-virtual-buffers -
When non-=nil=, add
recentf-modeand bookmarks toivy-switch-buffercompletion candidates.Adding this to the Emacs init file:
(setopt ivy-use-virtual-buffers t)will add additional virtual buffers to the buffers list for recent files. Selecting such virtual buffers, which are highlighted with
ivy-virtualface, will visit the corresponding file.
counsel- functions over their basic
equivalents in ivy-mode are:
- Multi-actions and non-exiting actions work.
ivy-resumecan resume the last completion session.- Customize
ivy-set-actions,ivy-re-builders-alist. - Customize individual keymaps, such as
counsel-describe-map,counsel-git-grep-map, orcounsel-find-file-map, instead of customizingivy-minibuffer-mapthat applies to all completion sessions.
ivy-read function. It takes
two required arguments and many optional keyword arguments. The
optional :action argument is highly recommended for features such as
multi-actions, non-exiting actions, ivy-occur and ivy-resume.
prompt-
A prompt string normally ending in a colon and a space.
ivy-count-formatis prepended to it during completion. collection-
Either a list of strings, a function, an alist or a hash table.
If a function, then it has to be compatible with
all-completions.
predicate-
Is a function to filter the initial collection. It has to be
compatible with
all-completions. Tip: sometimes it can be simpler to pre-filter thecollectionargument itself, e.g.:(cl-remove-if-not predicate collection). require-match- When set to a non-=nil= value, the input must match one of the candidates. Custom input is not accepted.
initial-input-
This string argument is included for compatibility with
completing-read, which inserts it into the minibuffer.It’s recommended to use the
preselectargument instead of this. history-
Name of the symbol to store history. See
completing-read. preselect-
Determines which one of the candidates to initially select.
When set to an integer value, select the candidate with that index value.
When set to any other non-=nil= value, select the first candidate matching this value. Comparison is first done with
equal. If this fails, and when applicable,preselectis interpreted as a regular expression.Every time the input becomes empty, the item corresponding to
preselectis selected. keymap-
A keymap to be composed with
ivy-minibuffer-map. This keymap has priority overivy-minibuffer-mapand can be modified at any later stage. update-fn-
Is the function called each time the current candidate changes.
This function takes no arguments and is called in the
minibuffer’s
post-command-hook. Seeswiperfor an example usage. sort-
When non-=nil=, use
ivy-sort-functions-alistto sort the collection as long as the collection is not larger thanivy-sort-max-size. action- Is the function to call after selection. It takes a string argument.
unwind-
Is the function to call before exiting completion. It takes no
arguments. This function is called even if the completion is
interrupted with
C-g. Seeswiperfor an example usage. re-builder-
Is a function that takes a string and returns a valid regexp.
See
Completion Stylesfor details. matcher-
Is a function that takes a regexp string and a list of strings and
returns a list of strings matching the regexp. Any ordinary Emacs
matching function will suffice, yet finely tuned matching
functions can be used. See
counsel-find-filefor an example usage. dynamic-collection-
When non-=nil=,
collectionwill be used to dynamically generate the candidates each time the input changes, instead of being used once statically withall-completionsto generate a list of strings. Seecounsel-locatefor an example usage. caller-
Is a symbol that uniquely identifies the function that called
ivy-read, which may be useful for further customizations.
Only the first two arguments (along with action) are essential —
the rest of the arguments are for fine-tuning, and could be omitted.
The action argument could also be omitted — but then ivy-read
would do nothing except return the string result, which you could
later use yourself. However, it’s recommended that you use the
action argument.
(defun counsel-describe-function ()
"Forward to `describe-function'."
(interactive)
(ivy-read "Describe function: "
(let (cands)
(mapatoms
(lambda (x)
(when (fboundp x)
(push (symbol-name x) cands))))
cands)
:keymap counsel-describe-map
:preselect (ivy-thing-at-point)
:history 'counsel-describe-symbol-history
:require-match t
:action (lambda (x)
(describe-function (intern x)))
:caller 'counsel-describe-function))Here are the interesting features of the above function, in the order that they appear:
- The
promptargument is a simple string ending in “: “. - The
collectionargument evaluates to a (large) list of strings. - The
keymapargument is for a custom keymap to supplementivy-minibuffer-map. - The
preselectis provided byivy-thing-at-point, which returns a symbol near point. Ivy then selects the first candidate from the collection that matches this symbol. To select this preselected candidate, aRETwill suffice. No further user input is necessary. - The
historyargument is for keeping the history of this command separate from the common history inivy-history. - The
require-matchis set totsince it doesn’t make sense to calldescribe-functionon an uninterned symbol. - The
actionargument callsdescribe-functionon the interned selected candidate. - The
callerargument identifies this completion session. This is important because, with the collection being a list of strings and not a function name, the only other way forivy-readto identify “who’s calling” and to apply the appropriate customizations is to examinethis-command. Butthis-commandwould be modified if another command calledcounsel-describe-function.
Async collections suit long-running shell commands, such as locate.
With each new input, a new process starts while the old process is
killed. The collection is refreshed anew with each new process.
Meanwhile the user can provide more input characters (for further
narrowing) or select a candidate from the visible collection.
(defun counsel-locate-function (str)
(or
(ivy-more-chars)
(progn
(counsel--async-command
(format "locate %s '%s'"
(string-join counsel-locate-options " ")
(counsel--elisp-to-pcre (ivy--regex str))))
'("" "working..."))))
;;;###autoload
(defun counsel-locate (&optional initial-input)
"Call the \"locate\" shell command.
INITIAL-INPUT can be given as the initial minibuffer input."
(interactive)
(ivy-read "Locate: " #'counsel-locate-function
:initial-input initial-input
:dynamic-collection t
:history 'counsel-locate-history
:action (lambda (file)
(when file
(with-ivy-window
(find-file file))))
:unwind #'counsel-delete-process
:caller 'counsel-locate))Here are the interesting features of the above functions, in the order that they appear:
counsel-locate-functiontakes a string argument and returns a list of strings. Note that this is incompatible withall-completions, but since we’re not using that here, we might as well use one argument instead of three.ivy-more-charsis a simple function that returns, e.g.,'("2 chars more")asking the user for more input.counsel--async-commandis a very easy API simplification that takes a single string argument suitable forshell-command-to-string. So you could prototype your function as non-async usingshell-command-to-stringandsplit-stringto produce a collection, then decide that you want async and simply swap incounsel--async-command.counsel-locateis an interactive function with an optionalinitial-input.#'counsel-locate-functionis passed as thecollectionargument.dynamic-collectionis set tot, since this is an async collection.actionargument uses thewith-ivy-windowwrapper, since we want to open the selected file in the same window from whichcounsel-locatewas called.unwindargument is set to#'counsel-delete-process: when we pressC-gwe want to kill the running process created bycounsel--async-command.callerargument identifies this command for easier customization.
(defun find-candidates-function (str _pred _)
(let ((props '(1 2))
(strs '("foo" "foo2")))
(cl-mapcar (lambda (s p) (propertize s 'property p))
strs
props)))
(defun find-candidates ()
(interactive)
(ivy-read "Find symbols: "
#'find-candidates-function
:action (lambda (x)
(message "Value: %s"
(get-text-property 0 'property x)))))Here are the interesting features of the above function:
find-candidates-functionbuilds up a list of strings and associates “foo” with the value 1 and “foo2” with 2.find-candidatesis an interactive function.#'find-candidatesis passed as thecollectionargument.actiongets passed the selected string with the associated value. It then retrieves that value and displays it.