我的.vimrc有一个字符串"set tabstop = 4",但是当我打开一些东西时它不适用,例如python文件.这是我的完整.vimrc:
cnoremap Q q
au! BufWritePost .vimrc source %
set tabstop=4
set shiftwidth=4
set smarttab
set expandtab
set softtabstop=4
set autoindent
"set syntax=off
set t_co=256
Run Code Online (Sandbox Code Playgroud)
strace说vim读取/home/user/.vimrc,并且他真的读取了这个文件,例如,cnoremap有效,他取代:Q by:q如预期的那样,但是如果我,例如,取消注释set syntax=off,则不适用.另外,vim -V2接下来说:
...
?????????? ???????? "$HOME/.vimrc"
????? "syntax/off.vim syntax/off/*.vim" ? "/home/user/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/home/user/.vim/after"
not found in 'runtimepath': "syntax/off.vim syntax/off/*.vim"
...
Run Code Online (Sandbox Code Playgroud)
当然,我想,这是有选择的东西.但如果我在编辑器中制作:so $MYVIMRC,他会应用所有设置!
现在我使用bash别名vim ="vim -S~/.vimrc",并且在详细模式下,他应用.vimrc没有错误并按预期工作,但这是奇怪的解决方案.
这可能有什么问题?为什么vim不应用.vimrc中的tabstop /语法?
输出 :verb set ts
tabstop=8
? ????????? ??? ????? ???????? ? /usr/share/vim/vim80/ftplugin/python.vim
Run Code Online (Sandbox Code Playgroud)
输出:脚本名称
1: /etc/vimrc
2: /usr/share/vim/vim80/syntax/syntax.vim
3: /usr/share/vim/vim80/syntax/synload.vim
4: /usr/share/vim/vim80/syntax/syncolor.vim
5: /usr/share/vim/vim80/filetype.vim
6: /usr/share/vim/vimfiles/ftdetect/dockerfile.vim
7: /usr/share/vim/vimfiles/ftdetect/nginx.vim
8: /usr/share/vim/vimfiles/ftdetect/stp.vim
9: /usr/share/vim/vim80/ftplugin.vim
10: ~/.vimrc
11: /usr/share/vim/vim80/plugin/getscriptPlugin.vim
12: /usr/share/vim/vim80/plugin/gzip.vim
13: /usr/share/vim/vim80/plugin/logiPat.vim
14: /usr/share/vim/vim80/plugin/manpager.vim
15: /usr/share/vim/vim80/plugin/matchparen.vim
16: /usr/share/vim/vim80/plugin/netrwPlugin.vim
17: /usr/share/vim/vim80/plugin/rrhelper.vim
18: /usr/share/vim/vim80/plugin/spellfile.vim
19: /usr/share/vim/vim80/plugin/tarPlugin.vim
20: /usr/share/vim/vim80/plugin/tohtml.vim
21: /usr/share/vim/vim80/plugin/vimballPlugin.vim
22: /usr/share/vim/vim80/plugin/zipPlugin.vim
23: /usr/share/vim/vim80/syntax/python.vim
24: /usr/share/vim/vim80/ftplugin/python.vim
Run Code Online (Sandbox Code Playgroud)
如果命令:verbose set tabstop?在 python 缓冲区中的输出是:
tabstop=8
? ????????? ??? ????? ???????? ? /usr/share/vim/vim80/ftplugin/python.vim
Run Code Online (Sandbox Code Playgroud)
这意味着文件类型插件/usr/share/vim/vi80/ftplugin/python.vim将您的'tabstop'选项的值设置为当前 python 缓冲区的本地值,8而您想要4.
您的设置set tabstop=4不会在 python 缓冲区中生效,因为本地值优先于全局值。
如果你想覆盖它,你可以创建文件~/.vim/after/ftplugin/python.vim并在里面写:
setlocal tabstop=4
Run Code Online (Sandbox Code Playgroud)
或者你可以在你的里面添加以下 autocmd vimrc:
augroup my_python_settings
autocmd!
autocmd FileType python setlocal tabstop=4
augroup END
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
687 次 |
| 最近记录: |