2

In .vimrc there is a line set expandtab, but sometimes this doesn't work. The problem is When I press tab key a new tab is inserted and it is not expanded to space. I can see the 'tab' is there with set list.

:scriptnames listing shows .vimrc has been loaded, but the problem is still there sometimes. and I have to run set expandtab by hand each time.
1: ~/.vimrc

And there are other similar issues it seems the .vimrc is actually not loaded. Any idea what is problem?

UPDATE verb set expandtab? or other similar commands all return noexpandtab
Last set from ~/.vimrc.
The log is pasted here. It includes my .vimrc, grep -rI result and the trace of VIM -V9.
The expandtab issue doesn't happen all the time, I'll update this post whenever it happens next time. The other issue always happening is set autoindent not working. verb set autoindent shows it is not set, see the trace around the last lines. But actually it is set already in .vimrc, and I have to set it by hand each time. Which is similar to expandtab issue.

2
  • When you captured that data did the apparent issue processing vimrc occur?
    – Argonauts
    May 17, 2016 at 4:33
  • Reading viminfo file "~/.viminfo" info oldfiles "hello.rb" "hello.rb" 4L, 37C Reading viminfo file "~/.viminfo" marks. Yes, from the log at line#303 I can see info like this when I am opening the file hello.rb and editing it.
    – canoe
    May 17, 2016 at 23:33

1 Answer 1

1

When you see this behavior, check to see if expandtab is set with this command:

:set expandtab?

If it is not set vim will return noexpandtab, and it means something changed it after .vimrc was processed - a plugin, a file sourced by .vimrc which creates a race condition with which setting is applied last, etc.

There are a few different ways to set it, so you have to check each of them. The following command will tell what last set expandtab:

:verb set expandtab?

Also check et, alias for expandtab, e.g. :verb set et? and invexpandtab, which toggles expandtab off/on, :verb set invexpandtab?

That should show you by what the .vimrc setting is getting overwritten.

If you find that the expandtab value is set appropriately, and tabs are not being converted to spaces, that's an entirely different issue - post an update to your question if that's the case.

Update:

Since its telling you that .vimrc is the last to set it, there must be something in there directly or indirectly that's doing it. Your best bet is to post your .vimrc on pastebin or similar and post a link to it.

You can also put 'set expandtab' as the last thing in .vimrc as it is processed sequentially.

You mentioned other settings not lining up with vimrc set values - which ones?

I would also grep through the .vim directory and subdirectories for expandtab , but you'll likely get a ton of false positives. If you do that, grep -rI expandtab ~/.vim, it could lead back us back to where in .vimrc it could be getting pulled in from.

Also - try creating a debug log and reviewing it for any errors warnings etc, especially (obv.) any that include 'expandtab'

running vim with the -V[N] option will do a pretty hefty runtime log, here N is the debug level.

vim -V9myVimLog

would create a log of debug level 9 in the current directory with the filename "myvimlog"

From another question

Best bet is to post your .vimrc. Make sure to obfuscate any personal info.

2
  • updated. no luck. What's the other different issue?
    – canoe
    May 16, 2016 at 5:26
  • This is a very interesting summary of some debugging techniques. I didn't know of the ? functionality to :set and that's very useful to me even if most of the time it's not. It reminds me of the ternary operator ?: in C (which many frown upon esp when nesting it but for whatever reason I don't have a difficult time parsing it in my head but then again that's just how I am). I've bookmarked this because it might be useful for me in the future. I should point out that although it's tagged macos it's still more general (not that I think others wouldn't put that together).
    – Pryftan
    Oct 14, 2018 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .