Rather than choosing one character to be displayed as the EOL character, I'd like one to display for both CR and LF separately and regardless of if the file is unix or dos. Is this possible?
With some caveats, you can do this using Vim's binary mode. It seems you might want to use the command
vim -b +'set list' somefile
Alternatively, you can put the following in your .vimrc
:
:set binary
:set list
The important thing is that binary mode must get set before the file in question is read into a buffer. Once Vim has read the file in, it's too late; this trick relies on changing how Vim reads the file in. Specifically, what you need is for Vim to not attempt to guess the file's particular type of <EOL>
.
Binary mode does what you want, disabling this automatic line-separator detection, but it does quite a few other things as well:
- sets
'textwidth'
to 0 - sets
'wrapmargin'
to 0 - unsets
'modeline'
- unsets
'expandtab'
So you might not want to have this in your .vimrc
; it might be better to use the command-line version, and only for those files where you need this special kind of display.
For more information:
:help 'binary'
:help edit-binary
:help file-read
:help file-formats
:help 'fileformat'
-
but it does quite a few other things as well
is this because binary is aFileType
with some auto commands or is it some sort of built in, unavoidable thing? – Captain Man Sep 14 '16 at 14:36 -
By that phrase, I meant to introduce the list that immediately follows it. – Ptolemarch Sep 14 '16 at 14:49
-
Right, I just didn't quote the whole thing :) What I meant was does it do those things because it uses some
FileType
calledbinary
with those auto commands or was it just some built in thing? – Captain Man Sep 14 '16 at 14:54 -
1Ah, right. None of this has anything to do with file types (but it is quite caught up in file formats). this is part of binary mode itself. See
:help 'binary'
. And maybe:help 'fileformat'
. – Ptolemarch Sep 14 '16 at 14:59
If you add to your ~/.vimrc
:
set ffs=unix
set list
That will always show CR
as ^M
and LF
as $
.
By default, vim would interpret a file that only has CRLF
endings as a dos file and show CRLF
as $
. By setting ffs=unix
, you force vim to always open as a unix file, and therefore the CR is treated as an extra character.
Note: Be careful if modifying and saving dos files though. If you press ENTER
, it will only insert a LF
. You would need to manually insert a CR
by typing CTRL+V, CTRL+M
.
Hello%$
for DOS files (where%
is a CR and$
is aLF
)? This isn't possible with thelist
/listchars
setting, and I can't really come up with a way to do this in VimScript either... – Martin Tournoij Feb 5 '16 at 6:51set list
is there a way to haveCR
andLF
show as specific characters maybe? – Captain Man Feb 5 '16 at 14:59set stl+=\ [%{&ff=='mac'?'CR':&ff=='unix'?'LF':'CRLF'}]
– Antony Sep 15 '16 at 13:41