Vim忽略.vimrc中指定的shiftwidth

Jit*_*esh 8 vim

我在Linux Mint 12"Lisa"(x64)上使用Vim 7.3.154 cli.

我更喜欢使用a tabstopshiftwidth2列.我.vimrc必须
:set ts=2
:set sw=2
完成同样的事情.

每当我打开一个新的Vim实例时,tabstop都会保留值,因此现有的选项卡会根据.vimrc.但不知何故,shiftwidth值变为3.这会在自动缩进时产生3列缩进.在新的Vim实例上
运行可以:set sw=2解决此问题.
谁能告诉我为什么Vim忽略/改变shiftwidth价值.vimrc

我试过禁用所有插件无济于事.

Vim编译选项 | 的.vimrc

gre*_*uan 6

这个答案只是总结了我们在评论中讨论的内容。:)

这很可能是因为您启用了文件特定设置。检查:h modeline更多信息。确保您遇到问题的那些文件中没有这一行。


除了设置之外tabstopshiftwidth您还应该设置更多关于空格和制表符的设置。

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
Run Code Online (Sandbox Code Playgroud)

查看此视频以获取更多信息:http : //vimcasts.org/episodes/tabs-and-spaces/


所以这是您能够解决的实际问题的答案。该php.php文件在/plugin目录中。每次 Vim 启动时,该目录都会加载一次。检查这个:http : //learnvimscriptthehardway.stevelosh.com/chapters/42.html#vimplugin

如果您想要该文件仅加载到 PHP 文件上,那么您应该将它放在/ftplugin文件夹中:http : //learnvimscriptthehardway.stevelosh.com/chapters/42.html#vimftplugin

阅读那里的文档,它应该是一个.vim文件,换句话说,在这种情况下它将被称为php.vim.

Pathogen 或 Vundle 所做的是修改运行时路径 ( :h runtimepath),仅此而已。

因此,您现在可以通过单击此答案左侧的绿色小箭头来接受此答案。:)

  • 读回来这绝对是我有史以来最好的答案。 (2认同)