1

For some reasons when I'm editing my ~/.config/nvim/init.vim, it adds 8 spaces even though I set set tabstop=4 on the file. Actually, :verbose set tabstop returns 4, so it should be 4 spaces.

I already read the questions here and here, and strangely, in Python I have no problem on adding 4 spaces.

What is causing the problem? How can I investigate the problem further and fix it up?

Blaszard
  • 545
  • 1
  • 9
  • 27
  • It shouldn't be inserting 4 spaces it should be adding a Tab. That is, unless you have some other settings with non-default values...particularaly 'expandtabs'. And what do you have for 'softtabstop', 'shiftwidth', 'cpoptions' while we're at it? This is only for *.vim files? Only when you simply hit Tab in Insert mode or other circumstances (e.g. autoindent scenarios)? – B Layer Jul 08 '18 at 22:27
  • Doesn't your init.vim file have a mode line? It's a comment in the file itself, by default in the 5 first or last lines which begin with " vim:" and allow to override some options like tabstop... – fievel Jul 08 '18 at 22:35
  • @fievel That's equivalent to :setlocal and would show up as the value returned by :set tabstop ... OP said that returns 4. – B Layer Jul 08 '18 at 22:44
  • Oh, and add your value for 'smarttab', too @Blaszard. – B Layer Jul 08 '18 at 22:52
  • @BLayer softtabstop is 4, and I found that the shiftwidth is set to 8. Setting it to 4 solved the problem, thanks. – Blaszard Jul 08 '18 at 23:19
  • Cool. We'll probably close this question since it does it lend itself to an answer useful to the general vim public. – B Layer Jul 08 '18 at 23:54
  • @BLayer It seems to me that confusion between tabstop, softtabstop, and shiftwidth is common enough to warrant a question? – Martin Tournoij Jul 09 '18 at 14:55
  • Related (but not duplicate as it doesn't cover shiftwidth): What is softtabstop used for? I'm surprised we don't have a question on this already! – Martin Tournoij Jul 09 '18 at 15:14
  • @MartinTournoij Certainly if there's a need for it I wouldn't argue against a q&a for 'shiftwidth', 'softtabstop', et al. But there are already answers that discuss them, AFAIK. The only way to add value, IMO, is to totally rewrite the question here to ask specifically about the settings. Otherwise, there are no better odds of someone wanting to know about them finding this page than any of the others. (Probably lower odds at this point since the others surely have more votes.) Is this kind of situation that calls for a community q&a? (If there is such a thing.) Otherwise just dup this..? – B Layer Jul 09 '18 at 17:19
  • BTW, my close vote was based on this criteria: "While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." since the resolution came about as a result of my follow up question comments. Anyways, I'm up for whatever best serves the community. – B Layer Jul 09 '18 at 17:30
  • Looks like this one could be considered the de-facto FAQ for tabs/spaces settings. (And while we're at it this one is a solid external reference.) – B Layer Jul 09 '18 at 21:14

0 Answers0