Vim ignores the shift width specified in .vimrc

I am using Vim 7.3.154 cli on Linux Mint 12 Lisa (x64).

I prefer using tabstop and shiftwidth of 2 columns. My .vimrc has :set ts=2
:set sw=2
do the same thing.

When I open a new instance of Vim, the value of tabstop preserved, so existing tabs are displayed according to .vimrc . But somehow, the shiftwidth value changes to 3. This leads to 3 column indentations during auto-deposition.
Execution :set sw=2 in a new instance of Vim fixes this problem.
Can someone tell me why Vim ignores / changes the shiftwidth value from .vimrc ?

I tried to disable all plugins to no avail.

Vim compiled options | .vimrc

+6
source share
1 answer

This answer simply summarizes what we discussed in the comments. :)

This is most likely due to the fact that you have certain file options. To learn more about this, check out :h modeline . Make sure that these files have problems that do not have this line.


Instead of setting only tabstop and shiftwidth , you should also set a couple more settings for spaces and tabs.

 set noexpandtab " Make sure that every file uses real tabs, not spaces set shiftround " Round indent to multiple of 'shiftwidth' set smartindent " Do smart indenting when starting a new line set autoindent " Copy indent from current line, over to the new line " Set the tab width let s:tabwidth=4 exec 'set tabstop=' .s:tabwidth exec 'set shiftwidth=' .s:tabwidth exec 'set softtabstop='.s:tabwidth 

Watch this video for more information: http://vimcasts.org/episodes/tabs-and-spaces/


So this is the answer to the actual problem that you were able to solve. This php.php file was located in the /plugin directory. This directory is loaded once, each time Vim starts. Check this out: http://learnvimscriptthehardway.stevelosh.com/chapters/42.html#vimplugin

If you want this file to be downloaded only to PHP files, you should put it in the /ftplugin folder: http://learnvimscriptthehardway.stevelosh.com/chapters/42.html#vimftplugin

Read the documentation there, it should be a .vim file, in other words, in this case it will be called php.vim .

What Pathogen or Vundle to do is change the execution path ( :h runtimepath ), nothing more, nothing more.

So now you can accept this answer by clicking on the little green arrow to the left of this answer. :)

+5
source

All Articles