How can I find out why vim keeps changing my expan

2019-03-18 09:56发布

问题:

I use vim. Specifically I am using Janus. I have expandtab set. However, during the course of using vim, for some reason, my expandtab setting gets set to noexpandtab, and my files start to gain hard tabs. I have tried typing :verbose set expandtab? but this does not show me anything (specifically, it shows me that noexpandtab is set, but it doesn't show a file that is responsible for setting it).

So I would like to find out:

  • Why my expandtab setting might be changing
  • How I can track down the culprit and prevent it from happening

Thanks

回答1:

Try this

:verb set expandtab?
:verb set et?
:verb set invexpandtab?

expandtab can really be set in a number of ways :/



回答2:

I should add that in addition to the above if you tried the following:

:verb set expandtab?
:verb set et?
:verb set invexpandtab?

And you get back with no line number or file:

noexpandtab

It's more than likely that you have the following and need to change the order:

set expandtab

set binary
set noeol

Change to (note the order)

set binary
set noeol

set expandtab

The reason for this is due to set binary command has a few defaults it executes after it runs. Including the following:

'textwidth'  will be set to 0
'wrapmargin' will be set to 0
'modeline'   will be off
'expandtab'  will be off

I noted DavidWinterbottom called this out in his comment, but that seemed to be the only comment that was hidden by default and this caused me to do a lot more reading that was necessary, so hopefully this post helps another poor soul from wasting countless hours tracking this down.



回答3:

VIM settings can either be set in a configuration file, or in a modeline inside the file you're editing. Note that expandtab can be shortened in VIM to et, so be sure to look for that as well.

Possible configuration files I'd look for:

  1. /etc/vim/vimrc and other files in that directory (sometime vimrc.local and such)
  2. $HOME/.vimrc

As for modelines, they are simply configuration options for VIM, located as comments in the file itself. If this only happens with some files but not others, look for comments that look something like:

/* vim: set noet ai tw=75: */

And try to remove them and see if it helps.



标签: vim janus