我现在是一个Python/Ruby多语言,需要根据我正在使用的文件类型切换我的.vimrc中的值.
我需要tabstop=2,softtabstop=2为Ruby和tabstop=4,softtabstop=4为Python.我的Google-fu未能如何做到这一点.有关如何检测文件扩展名的任何想法?
确保你有这个~/.vimrc:
filetype plugin on
Run Code Online (Sandbox Code Playgroud)
然后创建以下两个文件~/.vim/ftplugin:
在~/.vim/ftplugin/python.vim:
setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab
Run Code Online (Sandbox Code Playgroud)
在~/.vim/ftplugin/ruby.vim:
setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
Run Code Online (Sandbox Code Playgroud)
(我补充说shiftwidth,expandtab因为你几乎肯定也想要那些.)
Vim将检测文件类型,然后根据类型运行相应的文件.这很好,因为它会使你的混乱~/.vimrc.您可以对Vim识别的任何文件类型执行此操作.当您编辑文件时,您可以使用:set filetype?Vim认为它是什么类型的文件.