Emacs: icomplete, Name Completion
This page is for Emacs 28 (Released 2022-04) or later.
What is icomplete-mode
icomplete-mode
enhances emacs's name completion when in
minibuffer prompts.
icomplete does completion for any command that prompts for a list of choices, such as opening a file, switch buffer, calling a command by name.
Examples of commands that icomplete has effect:
execute-extended-command
find-file
switch-to-buffer
describe-function
- Alt+x
icomplete-mode
-
Turn on or off enhanced completion in minibuffer.
- Press Tab to complete.
- press Ctrl+j to select current choice and submit.
- press Enter to submit what's in minibuffer.
emacs 29 icomplete mode 2023-08-24 rWGf
icomplete-vertical-mode
icomplete-vertical-mode
- Activates
icomplete-mode
- Change settings to show choices vertically.
- Call again to toggle vertical display to horizontal.
icomplete-vertical-mode
is new in
Emacs 28 (Released 2022-04)

icomplete keys
- 【Tab】
- Complete what you typed.
- 【Space】
- Complete up to a word.
- 【Enter】
- Use what you typed so far.
- 【Ctrl+j】
icomplete-force-complete-and-exit
- Use first choice and exit.
- 【Ctrl+,】
icomplete-backward-completions
- complete backward
- 【Ctrl+.】
icomplete-forward-completions
- complete forward
- 【M-p】
previous-history-element
- 【M-n】
next-history-element
Completion Styles
you can setup many different completion styles.
here are different styles, from Completion Styles (Emacs Manual)
'basic
-
- A matching completion alternative must have the same beginning as the text in the minibuffer before point.
- Furthermore, if there is any text in the minibuffer after point, the rest of the completion alternative must contain that text as a substring.
'partial-completion
-
- This aggressive completion style divides the minibuffer text into words separated by hyphens or spaces, and completes each word separately.
- (For example, when completing command names,
em-l-m
completes toemacs-lisp-mode
.) - Furthermore, a ‘*’ in the minibuffer text is treated as a “wildcard”—it matches any string of characters at the corresponding position in the completion alternative.
'emacs22
-
- similar to
basic
, except that it ignores the text in the minibuffer after point.
- similar to
'substring
-
- A matching completion alternative must contain the text in the minibuffer before point, and the text in the minibuffer after point, as substrings (in that same order).
- Thus, if the text in the minibuffer is
foobar
, with point betweenfoo
andbar
, that matchesAfooBbarC
, where A, B, and C can be any string including the empty string.
'flex
-
if you typed
abc
it is matched against*a*b*c*
where * are any char or no char. 'initials
-
lch
matcheslist-command-history
Setup completion-styles
- completion-styles
-
variable.
List of completion styles to use.
The available styles are listed in
completion-styles-alist
.
;; examples of setting completion styles ;; use flex match. (setq completion-styles '(flex)) ;; default in emacs 29 (setq completion-styles '(basic partial-completion emacs22))
Icomplete Mode Setup
I recommend just turn on
icomplete-vertical-mode
and set flex match.
Put this in your Emacs Init File:
(when (not (version< emacs-version "28.1")) (progn ;; emacs 28.1 or later. use icomplete-vertical-mode and set flex match (setq completion-styles '(flex)) (icomplete-vertical-mode 1)))
(when (version< emacs-version "28.1") (progn ;; use ido mode for flex matching, and make it display vertical (progn ;; make buffer switch command do suggestions, also for find-file command (require 'ido) (ido-mode 1) ;; show choices vertically (setf (nth 2 ido-decorations) "\n") ;; show any name that has the chars you typed (setq ido-enable-flex-matching t) ;; use current pane for newly opened file (setq ido-default-file-method 'selected-window) ;; use current pane for newly switched buffer (setq ido-default-buffer-method 'selected-window)) (progn ;; minibuffer enhanced completion icomplete (require 'icomplete) (icomplete-mode 1) ;; show choices vertically (setq icomplete-separator "\n") (setq icomplete-hide-common-prefix nil) (setq icomplete-in-buffer t) (define-key icomplete-minibuffer-map (kbd "<right>") 'icomplete-forward-completions) (define-key icomplete-minibuffer-map (kbd "<left>") 'icomplete-backward-completions))))
History of Icomplete Mode
icomplete is originally written by Ken Manheimer, first released in 1993. (Ken Manheimer's home page: http://myriadicity.net/ • [2014-06-11 https://twitter.com/myriadicity ] )