I am using spacemacs + lsp layer (ccls) for c/c++ editing

Having my c-basic-offset set to 4:

  • if I select a region and press = (maybe invoking indent-region?), the region is indented by 2 spaces (messages: Applying [n] edits to [filename]).

  • If I press = without selecting a region, it indents with 4 spaces.

How can I control the indent level when indenting region?

  • 1
    Since you’re using lsp, it is probably using the language server to indent and not indent-region. Find out what command is run when you select a region and press = by first using C-h k and then hitting =.
    – scribe
    Commented Apr 28, 2020 at 8:41
  • Hi @scribe I didn't know the command C-h k. Thanks for letting me know helpful command. It turned out evil-indent was the function being invoked.
    – shpark
    Commented Apr 28, 2020 at 12:01
  • 1
    After investigating deeper, I found out indent-region-function was set to lsp-format-region. Now the question boils down to how I can change the behavior of lsp-format-function..
    – shpark
    Commented Apr 28, 2020 at 12:42
  • You can do C-h v to check the value of a variable as well. See what indent-tabs-mode is set to and what is tab-width. Setting those accordingly may help, read this for more information on the two variables.
    – scribe
    Commented Apr 28, 2020 at 13:48

1 Answer 1


I am not sure if this'll work, but this is out of my configurations adjusted for what you want.

(use-package cc-mode
  (defun my-c-mode-hook()
    (setq c-basic-offset 4
          c-label-offset 0
          tab-width 4
          indent-tabs-mode nil))
  (add-hook 'c-mode-hook 'my-c-mode-hook)
  (add-hook 'c-mode-hook 'lsp))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.