Question

In Powershell I run some command-line script and make a dump of it:

PS> cmd /c D:\script.bat | tee ~/out.log

Then, I open this log in vim, and this is roughly what I see:

яю^M^@
^@C^@:^@\^@U^@s^@e^@r^@s^@>^@s^@e^@t^@ ^@D^@E^@B^@U^@G^@_^@F^@U^@L^@F^@I^@L^@L^@M^@E^@N^@T^@=^@-^@X^@r^@u^@n^@j^@d^@w^@p^@:^@t^@r^@a^@n^@s^@p^@o^@r^@t^@=^@d^@t^@_^@s^@o^@c^@k^@e^@t^@,^@a^@d^@d^@r^@e^@s^@s^@=^@3^@0^@0^@4^@,^@s^@e^@r^@v^@e^@r^@=^@y^@,^@s^@u^@s^@p^@e^@n^@d^@=^@n^@ ^@^M^@

And the hex dump:

0000000: d18f d18e 0d00 0a00 4300 3a00 5c00 5500  ........C.:.\.U.
0000010: 7300 6500 7200 7300 3e00 7300 6500 7400  s.e.r.s.>.s.e.t.
0000020: 2000 4400 4500 4200 5500 4700 5f00 4600   .D.E.B.U.G._.F.
0000030: 5500 4c00 4600 4900 4c00 4c00 4d00 4500  U.L.F.I.L.L.M.E.
0000040: 4e00 5400 3d00 2d00 5800 7200 7500 6e00  N.T.=.-.X.r.u.n.
0000050: 6a00 6400 7700 7000 3a00 7400 7200 6100  j.d.w.p.:.t.r.a.
0000060: 6e00 7300 7000 6f00 7200 7400 3d00 6400  n.s.p.o.r.t.=.d.
0000070: 7400 5f00 7300 6f00 6300 6b00 6500 7400  t._.s.o.c.k.e.t.
0000080: 2c00 6100 6400 6400 7200 6500 7300 7300  ,.a.d.d.r.e.s.s.
0000090: 3d00 3300 3000 3000 3400 2c00 7300 6500  =.3.0.0.4.,.s.e.
00000a0: 7200 7600 6500 7200 3d00 7900 2c00 7300  r.v.e.r.=.y.,.s.
00000b0: 7500 7300 7000 6500 6e00 6400 3d00 6e00  u.s.p.e.n.d.=.n.
00000c0: 2000 0d00 0a                              ....

How do I configure vim to open such files normally without a hassle of deleting those nulls every time? P.S. Notepad opens file without nulls visible

Was it helpful?

Solution

It seems that your file is UTF8 encoded.

To open it, start vim with encoding argument like this:

vim "+set encoding=utf-8"

or if you are already editing the file, you can set the encoding as follows:

:set enc=utf-8

OTHER TIPS

Your file is encoded in UTF-16; each character is represented by 2 byte (and the lower end comes first).

As long as 'encoding' is set to something that can represent the characters in the file (utf-8 is recommended, latin1 won't do), this is fine, no need to fiddle with it.

You need to tell Vim the file's encoding. Either explicitly when opening

:edit ++enc=utf-16le out.log

or by prepending (after files with BOM, which can be uniquely identified) the value to 'fileencodings':

:set fileencodings=ucs-bom,utf-16le,utf-8,default,latin1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top