This chapter provides basic instructions for Company setup and usage.
Company package is distributed via commonly used package archives in a form of both stable and development releases. To install Company, type M-x package-install RET company RET.
For more details on Emacs package archives, see (emacs)Packages.
The package Company provides a minor mode company-mode.
To activate the company-mode, execute the command M-x company-mode that toggles the mode on and off. When it is switched on, the mode line (see (emacs)Mode line) should indicate its presence with an indicator ‘company’.
After company-mode had been enabled, the package auto-starts suggesting completion candidates. The candidates are retrieved and shown according to the typed characters and the default (until a user specifies otherwise) configurations.
To have Company always enabled for the following sessions, add the
(global-company-mode) to the Emacs configuration file
(see (emacs)Init File).
By default — having company-mode enabled (see Initial Setup) — a tooltip with completion candidates is shown when a user types in a few characters.
To initiate completion manually, use the command M-x company-complete.
To select next or previous of the shown completion candidates, use respectively key bindings C-n and C-p, then do one of the following:
Under the hood, mentioned in the previous section keys are bound to the commands of the out-of-the-box Company.
Select the next candidate (
Select the previous candidate
Insert the selected candidate (
Insert the common part of all the candidates
Cancel company-mode activity (
Display a buffer with the documentation for the selected candidate
Display a buffer with the definition of the selected candidate
The full list of the default key bindings is stored in the variables
Moreover, Company is bundled with a number of convenience commands that do not have default key bindings defined. The following examples illustrate how to assign key bindings to such commands.
(global-set-key (kbd "<tab>") #'company-indent-or-complete-common)
(with-eval-after-load 'company (define-key company-active-map (kbd "M-/") #'company-complete))
(with-eval-after-load 'company (define-key company-active-map (kbd "TAB") #'company-complete-common-or-cycle) (define-key company-active-map (kbd "<backtab>") (lambda () (interactive) (company-complete-common-or-cycle -1))))
In the same manner, an additional key can be assigned to a command or a command can be unbound from a key. For instance:
(with-eval-after-load 'company (define-key company-active-map (kbd "M-.") #'company-show-location) (define-key company-active-map (kbd "RET") nil))
For a more user-friendly output of the pre-defined key bindings, utilize M-x describe-keymap RET company-active-map or C-h f RET company-mode.