8

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

我更喜欢使用 2 列的tabstopshiftwidth。我.vimrc必须
:set ts=2
:set sw=2
完成同样的任务。

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

我尝试禁用所有插件无济于事。

Vim 编译选项 | .vimrc

4

2 回答 2

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

查看此视频以获取更多信息: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),仅此而已。

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

于 2013-01-05T18:10:49.523 回答
0

你可以运行:

verbose set shiftwidth ? 

检查什么设置了 shiftwidth 的值。它可能来自插件。您也可以选择在此处修改值。

于 2021-12-06T16:55:52.427 回答