On the first file I created, I had tabs set to 4 spaces and wasn't using the LSP yet. Then I enabled the LSP, and on all subsequently created files tabs are 2 spaces, yet on the original file, it keeps to 4 spaces. I'd prefer to have everything be 4 spaces, but I'd even be fine with everything being 2 spaces, as long as it's consistent. This inconsistent formatting is driving me insane.
1 Answer
lsp-mode documentation states the following:
settings that are controlled on
lsp-modelevel are indent size and whether the server should use tabs or spaces. Refer tolsp--formatting-indent-alistto find out what is the variable that is used for the current major mode.
Hence, looking at lsp--formatting-indent-alist, for the major-mode typescript-mode (for instance), set typescript-indent-level to the value you need/want, this way:
(setq typescript-indent-level 2) But this may differ depending on the actual setup you have (major-mode, package manager, etc). See the following lsp-mode discussions for additional examples:
- How to pass config to language server to ask it to format a file with less spaces.
- Make lsp-format-buffer respect editorconfig.
As another approach, try setting lsp-enable-indentation to nil. This should disable lsp-mode-caused indentation fully.