在 Vim 中处理代码缩进?
我在一个 4 人的工程团队工作,主要编写 javascript,偶尔涉足 ruby 和 python。因此,作为一个团队,我们一直共享代码,并且正如大多数程序员所做的那样,团队的每个成员都有他最喜欢的缩进和缩进级别。相关设置。我是团队中使用并喜爱 Vim 作为主要代码编辑器的 2 名成员之一。我爱我的团队,但我也喜欢我的缩进,它恰好使用 4 个空格制表符。有关更多上下文,这是我在 .vimrc 中使用的内容:
set ts = 4 sts = 4 sw = 4 expandtab " 4 space tabs
随着团队中进行大量代码共享和协作编辑,主要代码文件通常开始显示为大量混合选项卡和文件。空格混乱,因此即使是选择全部并按 =
进行智能缩进的经典 Vim 技巧也没有太大效果。
无论如何,我的问题是:在 Vim(特别是 MacVim)中,是否有更好(更可靠)的方法将代码文件从混乱的混合缩进转换为我喜欢的缩进?无论是 .vimrc 设置还是我在编辑文件时输入的命令,我都不在乎。
感谢您提前提出任何建议!
I work on an engineering team of 4 people, mostly writing javascript while occasionally dabbling in ruby and python. So, as a team, we share code all the time, and as most programmers do, each member of the team has his favorite level of indentation & related settings. I am one of 2 members of the team who use and love Vim as my primary code editor. I love my team but I also love my indentation, which happens to use 4-space tab characters. For more context, here's what I use in my .vimrc:
set ts = 4 sts = 4 sw = 4 expandtab " 4 space tabs
With so much code-sharing and collaborative editing going on in the team, the main code files usually start to appear as a mass of mixed tab & space mayhem, so that even the classic Vim trick of selecting all and pressing =
to smart indent doesn't have much effect.
Anyway, my question is this: In Vim (MacVim specifically) is there a better (more reliable) way of converting a code file from messy, mixed indentation to my preferred indentation? Whether it be a .vimrc setting or a command I enter while editing the file, I don't care.
Thanks for any suggestions in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
:retab
。话虽如此,我强烈建议您作为一个团队,在协作处理某个项目时同意并使用缩进样式。
Use
:retab
.Having said that, I strongly suggest that you, as a team, agree on and use an indentation style when working collaboratively on a certain project.
我们在同一家商店中也有使用 javascript 和 ruby 的相同情况。
我发现我喜欢 javascript 的 4 个空格,但 ruby 看起来只有两个空格更好。
我确实同意 Yaser 的观点,您需要设置标准(空格 FTW)
一旦您决定删除所有制表符,请使用 grep 查找文件:retab
We have the same case of using javascript and ruby in the same shop.
I find I like 4 spaces for javascript but ruby looks much better with just two spaces.
I do agree with Yaser, you need to set the standard (spaces FTW)
Once you decided to get rid of all the tab chars use grep to find the files to :retab