Created
December 23, 2019 07:47
-
-
Save cpusoft/8a76750f41b084140f52418282a5add7 to your computer and use it in GitHub Desktop.
vi下显示回车换行符等特殊符号
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vi下显示回车换行符等特殊符号 | |
| 在早期的打印机时代,开始新的一行要占用两个字符的时间。如果到了一行的结尾处,你要快速回到新的一行的开头,需要打印针头在纸面上飞快地掠过,常常会在纸面上留下污点。 | |
| 解决这个问题的办法就是,用两个字符:一个字符<Return>来移到第一列,另一个字符<Line feed>来新增一行。计算机产生以后,存储较为昂贵,在如何解决回车换行这个老问题上,人们产生了不同的意见。 | |
| UNIX人认为在到达一行的结尾时新增一行<Line feed> (LF),而Mac人则认同<Return> (CR)的解决办法,MS则坚持古老的<Return><Line feed> (CRLF)的方法。这就意味着如果你将一个文件从一个系统转移到另一个系统,就面临着回车换行的问题。而Vim编辑器则会自动的认出这种文件格式方面的区别,并做出相应处理。 | |
| :set fileformats=unix,dos | |
| unix文件格式作为第一选择,dos格式作为第二选择,尤其需要注意的是shell、python等脚本需要保存为unix格式,因为不然你在linux下直接运行时会提示:No such file or directory,因为Linux把换行符也当成脚本解释器的一部分了。 | |
| :set fileformat | |
| 查看文件格式 | |
| :set fileformat=unix/dos | |
| 设置(转换文件格式) | |
| :set endofline/noendofline | |
| 设置文件末尾是否自动增加换行符 | |
| :set list/nolist | |
| 设置是否显示不可见字符,注意此选项受set listchars约束 | |
| :%s/\n//g | |
| 删除换行符 | |
| :set fileformat 设置文件格式 | |
| :set endofline 设置文件结束符 | |
| :set noendofline 取消文件结束符 | |
| :set list 进入List Mode | |
| :set nolist 退出List Mode | |
| :%s/\n//g 删除换行符 | |
| :set textwidth 设置行宽 | |
| :set textwidth 设置行边距 | |
| :join 合并多行 | |
| J 合并两行 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment