Show line endings in old school sunos

I would like to see line endings in old school sunos. I would prefer vi but any way you can think of would be appreciated. What are the options for seeing both Line Feed and Carriage Return?

I am using an old school vi.

: uname -a
SunOS ah57ndcub04031 5.11 11.4.71.170.2 sun4v sparc sun4v non-global-zone
: vi --version
VIM - Vi IMproved 9.0 (2022 Jun 28)
Included patches: 1-393, 395-2136
Modified by Solaris Userland Team
Compiled by the Solaris Userland build environment

This does not do anything in vi.

:set ffs=unix

This shows ^M in vi. Vi needs to be running.

:e ++ff=unix

If you put this in ~/.vimrc it will show ^M. Do not understand why :set ffs=unix does nothing.

set ffs=unix

This points out to you what vi thinks you are are using.

:set ff?
:set ff

One of the most surprising ones to me. My cookies.txt was created in notepad++ with windows file endings so expected to see ASCII text, with CRLF line terminators

: file cookies.txt
cookies.txt:    ascii text

This is what I am used to seeing.

Unix:

$ file testfile1.txt
testfile.txt: ASCII text

"DOS":

$ file testfile2.txt
testfile2.txt: ASCII text, with CRLF line terminators

One of the few options that will show both Line Feed and Carriage Return. Line Feed = \n and Carriage Return = \r \n.

od -t c <filename>
od -c <filename>

Another option to see the Carriage Return.

less -u filename

One of the few options that will show both Line Feed and Carriage Return. 0D = Carriage Return and 0A = Line Feed. This is a hex dump so the numbers are different than what you expect.

xxd file name

Binary mode in vi will display ^M characters for carriage return. This does not work for some reason :set binary. I did check :help binary and it made it sound like it would work.

vim -b filename

You can do cat -vet myFile.
Or inside vi (in command mode) you can do :set list

Added the first one to my list of ideas. It only displays carriage return's though.

:set list only adds a $ to the end of the line. Tried in with both a unix file and windows file.

Can you think of anything that will show both Line Feed and Carriage Return?

:set list shows all special characters in vi; a CR is shown as ^M
The $ at the end of the line represents the newline.
vim can switch to WinDOS mode, showing [dos] at the bottom line, then it does not show the ^M before the $

Can you please explain how to make the ^M show up after putting in :set list? It does not show up. Is this a limitation of old vi? Only the $ shows up.

I think your vi is aliased or linked to vim. So you have vim, and it switches to WinDOS mode.

The "old school" vi would show ^M$

Do you know how this is done? I do not see vim in my alias list. I do not see vim when I do this. Note my display puts a : in front of commands. It does not bother me so I have not changed it.

: which vi
/usr/bin/vi

: type -a vi
vi is /usr/bin/vi
vi is /usr/ccs/bin/vi

When I do this it says vim so I do believe you are right. Do you know how they are doing it? I do not see a link or alias.

: vi --version
: \vi --version
:vi
:\vi

Is there a way to use old vi instead of vim? What do I need to do in vim to see the ^M?

How does your /usr/bin/vi look like?

ls -il /usr/bin/vi

But you might have a vim version where the vi is not visibly linked to vim (but uses the vim shared libraries.)

Some vim versions claim they behave like vi if they are run with the name vi. But some of them are buggy, it does not work. In this case try ex that might be linked to vim (visibly or not).

Try

vim -v filename

Also try to edit/create the file .exrc in your home director, and put a line set compatible

cd
echo "set compatible" > .exrc
touch .vimrc

The last command ensures that the file .vimrc exists. Most vim versions will process .exrc if run as vi, and if run as vim will process .vimrc in favor of .exrc.

In Solaris 11.x try

/usr/xpg4/bin/vi

that should be an "old school" vi.
(Likewise, if the /usr/bin/ex is a vim then /usr/xpg4/bin/ex is the old archaic ex.)

You are right about the link :). Is my which and type buggy for not showing me this? I thought they usually show that information.

: ls -il /usr/bin/vi
     54585 lrwxrwxrwx   1 root     root           3 Apr  9  2018 /usr/bin/vi -> vim

No difference with this.

vim -v filename

Is the set compatible a newer feature? The archaic ex does not seem to like it.

: /usr/xpg4/bin/ex cookies.txt
compatible: No such option - 'set all' gives all option values
"cookies.txt" [Incomplete last line] 3 lines, 7 characters
:
At EOF
:

Same with the archaic vi but after I hit enter it does show the ^M.

: /usr/xpg4/bin/vi cookies.txt
compatible: No such option - 'set all' gives all option values
Error detected in .exrc.[Hit return to continue]

After enter:

a^M
b^M
c

How do you make ex show your text. Doesn't seem to show any text from the file.

: /usr/xpg4/bin/ex cookies.txt
compatible: No such option - 'set all' gives all option values
"cookies.txt" [Incomplete last line] 3 lines, 7 characters
:
At EOF
:

The .exrc setting is for the /usr/bin/vi or /usr/bin/ex i.e. vim.
The /usr/xpg4/bin/vi always shows the ^M. If you go for this one then delete the .exrc

The /usr/xpg4/bin/ex is, well, archaic. It is not a "visual" editor. Not worth to learn it.