Skip to content

Switching from AC

Hans Chen edited this page Feb 13, 2017 · 13 revisions

company-mode and auto-complete-mode behave differently in terms of candidate selection and completion. There's a few tweaks you can do to make the switch less jarring. First of all, to make TAB complete first, then cycle, rebind it to company-complete-common-or-cycle:

(eval-after-load 'company
     (define-key company-active-map (kbd "TAB") 'company-complete-common-or-cycle)
     (define-key company-active-map (kbd "<tab>") 'company-complete-common-or-cycle)))

If you wish to have S-TAB as well to cycle the other way around:

(eval-after-load 'company
     (define-key company-active-map (kbd "S-TAB") 'company-select-previous)
     (define-key company-active-map (kbd "<backtab>") 'company-select-previous)))

The current candidate isn't displayed inline except when there's only one left. You can rectify this by switching out company-preview-if-just-one-frontend for company-preview-frontend:

(setq company-frontends

Finally, to cancel selections by typing non-matching characters, customize company-require-match:

(setq company-require-match 'never)

If you prefer it the other way around (keys like SPC finishing completion), customize company-auto-complete instead and for more control, company-auto-complete-chars as well:

(setq company-auto-complete t)

Setting up similar popup behavior

See for more info.

  (defun my-company-visible-and-explicit-action-p ()
    (and (company-tooltip-visible-p)

  (defun company-ac-setup ()
    "Sets up `company-mode' to behave similarly to `auto-complete-mode'."
    (setq company-require-match nil)
    (setq company-auto-complete #'my-company-visible-and-explicit-action-p)
    (setq company-frontends '(company-echo-metadata-frontend
    (define-key company-active-map [tab]
    (define-key company-active-map (kbd "TAB")


When using (company-ac-setup), the color of faces of the completions (company-preview and company-preview-common) might be different. If this is not preferred, to get matching colors, this is an option:

    (eval-after-load 'company
      (lambda ()
         :background (face-attribute 'company-preview-common :background))))

Similar popup colors

(From the company-go README)

       ((t (:foreground "darkgray" :underline t))))
       ((t (:inherit company-preview))))
       ((t (:background "lightgray" :foreground "black"))))
       ((t (:background "steelblue" :foreground "white"))))
       ((((type x)) (:inherit company-tooltip :weight bold))
        (t (:inherit company-tooltip))))
       ((((type x)) (:inherit company-tooltip-selection :weight bold))
        (t (:inherit company-tooltip-selection)))))
You can’t perform that action at this time.