保存文件时,这些是我在 TextMate (Mac OS X) 中的默认设置:
文件编码:UTF8(推荐)行尾:LF(推荐)
如何设置 VIM 以保存与 TextMate 具有相同文件编码和行尾的文件?我将不胜感激任何建议。谢谢!
" Stick with the UTF-8 encoding.
if has('multi_byte')
" Encoding used for the terminal.
if empty(&termencoding)
let &termencoding = &encoding
endif
" Encoding used in buffers, registers, strings in expressions, "viminfo"
" file, etc.
set encoding=utf-8
" Encoding used for writing files.
setglobal fileencoding=utf-8
endif
" Use both Unix and DOS file formats, but favor the Unix one for new files.
set fileformats=unix,dos
Run Code Online (Sandbox Code Playgroud)
注意:最后一行的优点是两种格式都在 Vim 缓冲区中正确显示。例如,如果您删除dos
from fileformats
,那么dos
从现在起您将在 Vim 中打开的所有文件都将^M
在行尾处被符号弄得乱七八糟。这^M
不是别的,但\r
在这种情况下,Vim 将无法正确解释。因此,强烈建议保持fileformats
如上图所示。不用担心,您创建的任何新文件都将unix
默认使用格式(如上面的评论中所述)。
如果您遇到一些具有dos
格式的文件并想将其转换为unix
.
:set ff=unix
Run Code Online (Sandbox Code Playgroud)