crlf换行 idea_IntelliJ Idea设置默认换行符

本文介绍了如何在IntelliJ IDEA中将默认换行符设置为LF,以解决Windows与Linux系统间的编译问题。通过步骤:File->Other Settings->Default Settings->Editor->Code Style,选择LF作为新文件的行分隔符,确保代码在不同系统下的一致性。
摘要由CSDN通过智能技术生成

在window下开发有一个大坑,就是换行默认是CRLF,也就是回车换行,但是Linux下只有换行LF,这样代码提交后,会出现编译问题,所以最好的办法是在IntelliJ下设置默认为LF。首先我们先介绍CRLF,LF和CR这三种东西,CR是MAC老版本的做法,就是回车,但是后来的MAC系统统一换成LF了,LF是Linux下的做法,就是换行,这个做法比较自然,为什么要回车换行呢,是吧。微软采用的是CRLF,看上去好像是兼容了CR和LF,但是实际完全不是那么回事,就是回车并换行,好鸡肋啊,微软一直保持这种做法,开发人员大多在Linux下,所以对于开发人员来说还是比较坑的。下面介绍设置详解:

###第一步:File->Other Settings->Default Settings

20180110224854860962.png

###第二步:Editor->Code Style

可以看到,默认是System-Dependent,这个其实还是很牛叉的,根据系统自动配置,但是你是windows系统,默认是CRLF,服务器是Linux,你就得自己换了。

20180110224854861939.png

我们设置成下面这样,保存就好了

20180110224854863892.png

创建文件时,就能看到默认是LF了

参考网址是IntelliJ的使用,不熟悉的话,可以看看,这个文档还是写的不错的,就是全是英文,对于英文不好的人来说,略坑。

参考网址: [https://www.jetbrains.com/idea/help/configuring-line-separators.html]

Configuring Line Separators

IntelliJ IDEA makes it possible to set up line separators (line endings) for the newly created files, and change line separator style for the existing files.

On this page:

To set up line separators for new files

In Settings, click Code Style.

From the Line separator (for new files) drop-down list, select the desired line separator style:

774aaeca81bc34ddba53d9238500659b.png

Apply changes and close the dialog.

To view line ending style for the current file

Open the desired file in the editor, as described in the section Opening and Reopening Files.

View the Status bar: the current line endings style is denoted by the dedicated icon with the specified style, for example,

5da9f5f484904d76d122bd107938f8b0.png.

To change line separator for a file, currently opened in the editor

Open the desired file in the editor, as described in the section Opening and Reopening Files.

Do one of the following:

Click the line separator spin box in the Status bar, and choose the desired line ending style from the pop-up menu:

38a328a743e6ee9d8d327f99356f329e.png

Choose File | Line Separators on the main menu, and then choose the desired line ending style from the sub-menu.

To change line separator for a file or directory, selected in the Project view

Select a file or directory in the Project tool window.

Note that if a directory is selected, the line ending style applies to all nested files recursively.

Choose File | Line Separatorson the main menu, and then select the desired line ending style from the sub-menu.

27f02d0c445e9b45aa10457b0d284428.png

Tips and tricks

Use multiple selection in the Project view.

Changing line separator is reflected in the Local history of a file.

Run the inspection ‘Inconsistent line separators‘ to find out, which files use line separator different from project‘s default.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值