At the moment, this is just a dumping ground for useful tidbits I find / need in my daily work. At some point I will get around to organizing and formalizing.
File formats (carriage returns)
If you ever diff two files that look identical, but they display as completely different, you may be dealing with a file format issue. This may happen if you are sharing files between different OS. To display the file format of your current file type this:
:set ff? ffs?`
The first command (ff?
) will tell the format of the current file. The second (ffs?
) tells you the file formats supported by your OS.
To change the file format of a file (and its line terminators), type:
:set ff=unix
where unix
can be one of unix
(linux and Mac OS X or later), mac
(Mac OS 9 and earlier) or dos
(Windows). Alternatively, you can use :e ++ff=unix
to convert a windows file to unix/mac. After either option, be sure to :w
rite your file.
If you want to get rid of all Windows line terminators (^M
or CRLF
), you can get visual confirmation by closing your file and reopening it in binary mode:
vi -b some-file`
As always, there are a million edge cases, so if any of the above doesn’t work, this entry in the Vim wiki is quite useful.