求教根据不同文件类型,自动切换缩紧

2021-01-09 20:00:45 +08:00
 AmitabhaPk
各位大佬,求教如何配置 vimrc,根据 filetype 匹配缩紧类型

比如在 kernel 写代码时,要用 TAB 缩进,但在应用层写 cpp 代码要求 4 个空格缩紧,不会配置,每次切换时 都要手动修改 vimrc 。。。。。
1982 次点击
所在节点    Vim
7 条回复
odirus
2021-01-09 20:03:54 +08:00
yzbythesea
2021-01-09 20:04:57 +08:00
autocmd Filetype cpp set softtabstop=4
zhanglintc
2021-01-09 20:22:40 +08:00
这是我的,正常是 4 个空格缩进,如果是 ruby 、html 等,就是 2 个缩进。
你看着改改就行了。

" general indent setting
set tabstop=4 " ts
set softtabstop=4 " sts
set shiftwidth=4 " sw
set expandtab
set smarttab

" languages specific indent setting
autocmd FileType ruby,html,xml,smarty setlocal ai ts=2 sts=2 sw=2

ai => autoindent
ts => tabstop
sts => softtabstop
sw => shiftwidth
AmitabhaPk
2021-01-09 20:23:09 +08:00
@yzbythesea 我刚才设置成 tabstop=4 expendtab 就好了 多谢!
AmitabhaPk
2021-01-09 20:24:37 +08:00
@zhanglintc 哈哈 收了 现在还不会这么多。。。。
AmitabhaPk
2021-01-09 20:28:57 +08:00
@odirus 这个很好 读一下配置上
IgniteWhite
2021-01-10 10:24:42 +08:00
我的 https://github.com/g6ai/dotfiles

" Tab
filetype indent on
set expandtab " Always use space instead of tab
autocmd FileType vim setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType sh setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType python setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType tex setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4

nathanaelkane/vim-indent-guides 这个插件也不错

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/743395

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX