设置编辑器:缩进和编码

发布于 2024-08-06 08:19:14 字数 135 浏览 2 评论 0原文

我正在与一些朋友开发一个小项目,我们面临一些缩进问题。我们每个人都使用不同的编辑器(我们都有不同的最爱:),而且我们也使用不同的操作系统。

能够一起开发并设置我们的编程编辑器以使缩进和编码相同的最佳解决方案是什么?您推荐什么设置以及为什么?

I'm developing a small project with some friends and we're facing some indentation issues. Each of us is using a different editor (we all have different favorites :) and we also are on different operating systems.

What is the best solution to be able to all develop together and set our programming editors so indentation and encoding is the same? What settings do you recommend and why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦在深巷 2024-08-13 08:19:14

您应该让版本控制系统处理行结束问题。在 SVN 中,“svn:eol-style”属性可以设置为“native”来处理自动转换行结尾。我假设您的代码是 ASCII 或 UTF8,因此您不会遇到字符编码问题。

就格式而言,您必须大致选择某种样式,例如放置大括号的位置,但只要使用相同数量的缩进,就没有理由必须具有相同的缩进样式。这是一个令人困惑的说法,所以请允许我解释一下:几乎每个 IDE 都能够将制表符宽度设置为您想要的任何值。如果一名团队成员喜欢缩进 2 个字符宽度,另外一个是 4 个字符宽度,那也可以。文件中存储的一个制表符可以根据 IDE 设置以任一方式显示。只需将 IDE 配置为使用制表符缩进,然后根据需要设置制表符宽度即可。

(冒着引发激烈战争的风险,这就是为什么我坚定地站在选项卡与空格之战中的选项卡阵营。奇怪的是,空间人们似乎认为这个功能就是使用空格的原因......我永远不会了解他们)。

You should have your version control system handle the line ending problems. In SVN, the "svn:eol-style" property can be set to "native" to handle auto-converting the line endings. I assume your code is ASCII or UTF8 so you don't have problems with character encoding.

As far as formatting goes, you'll have to choose roughly some style, such as where to put the braces, but there's no reason you have to have the same indent style, provided you use the same number of indents. That's a confusing statement, so allow me to explain: nearly every IDE ever has the ability to set tab widths to any value you want. If one team member likes to indent 2 character widths, another 4, that's fine. One tab character stored in the file can display either way based on IDE settings. Just configure your IDE to indent with tabs and then set the tab widths per your desires.

(at the risk of starting a flame war, this is why I am solidly in the camp of tabs in the tabs vs spaces war. strangely, the spaces folks seem to consider this very feature the reason to use spaces... I will never understand them).

喜爱皱眉﹌ 2024-08-13 08:19:14

如果您都坚持拥有自己的缩进设置,那么您将需要专门使用制表符来缩进代码。 (前提是您的各个编辑都支持这一点)。

这种方法违背了使用空格且仅使用空格来缩进的普遍共识。

If you are all insistent to have your own indentation settings, then you will need to use exclusively the tab character to indent the code. (Provided your various editors support this).

This approach is counter to the general consensus of using spaces and only spaces for indenting purposes.

忆悲凉 2024-08-13 08:19:14

无论您做什么,我建议将制表符转换为常用的空格数。我知道 Eclipse 可以即时完成此操作,但我不确定像 gvim 这样的编辑是否可以。无论如何,对于所有空格,各个编辑器/IDE 无法解释一个选项卡由多少个空格组成。另外,如果有人使用 Windows 编辑器/IDE,请将其设置为使用 Unix 风格的换行符,这样当您在不同的操作系统中编辑时,就不会在每行末尾看到烦人的 ^M。

Whatever you do, I recommend converting tabs to a common number of spaces. I know Eclipse can do this on the fly, but I'm not sure if edits like gvim can. In any case, with all spaces it is not up to the individual editors/IDEs to interpret how many spaces make up a tab. Also, if anyone's using a Windows editor/IDE, set it to use Unix-style newlines, so that you don't get the annoying ^M at the end of every line when you edit in a different OS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文