我想为不同的语言或文件类型设置不同的设置。
每种语言都有自己的样式指南(例如,不同的制表符大小、空格而不是制表符等等)所以我不能在我的.vimrc
中添加设置,因为我在几种语言中都使用了vim。每种语言的设置应该是分开的。
Python文件设置为4个空格缩进样式:
set tabstop=4
set shiftwidth=4
两个空格缩进样式的JavaScript文件设置:
set tabstop=2
set shiftwidth=2
发布于 2021-07-31 06:50:19
autocmd FileType python call Python_settings()
function! Python_settings()
setlocal tabstop=4
setlocal shiftwidth=4
setlocal expandtab
endfunction
发布于 2021-07-31 06:54:59
Vim提供了内置的文件类型检测,除其他外,它使得对不同的文件类型进行不同的操作成为可能。
要使该机制正常工作,您需要在vimrc
中使用以下任何一行
filetype on
filetype indent on
filetype plugin on
filetype indent plugin on " the order of 'indent' and 'plugin' is irrelevant
f 211
假设您有以下任何一行:
filetype plugin on
filetype indent plugin on
您可以创建具有以下内容的$HOME/vim/after/ftplugin/javascript.vim
:
setlocal tabstop=2
setlocal shiftwidth=2
使用
:setlocal
而不是:set
使这些设置成为本地设置,从而防止它们泄漏到其他缓冲区。after
目录用于确保您的设置是最后来源的。。
假设您已经启用了ftplugins,那么Python就没有什么可做的了,因为默认的ftplugin已经以您想要的方式设置了这些选项。
https://stackoverflow.com/questions/68602979
复制相似问题