Windows7 PowerShell inserts ^ @ between all characters - how to prevent?

I hope it would be trivial for you to answer.

I have gvim and vim on Win7. Each time I redirect the result of a command to a file and open it with Vim (or Gvim, the same effect), I have a binary 0 (^ @ sign) inserted between all characters.

So instead

r96130

I have

^@r^@9^@6^@1^@3^@0^@

Any idea how to (preferably) prevent it or (fine) to get rid of it?

I tried the substitution, but obviously it is not just ^ @, it is binary zero (I think) so that it does not go up /^@.

Edit (s):

1) I tried the encoding settings for UTF-8 (encoding the content I'm working on) and UTF-16 (for @Philippe Wendler's answer, thanks), to no avail.

2) __ PowerShell__ . ( cmd), . , PowerShell, .

3) Powershell, @Christian, . , Ubuntu Vim , "" PowerShell + Vim, , , .: -)

@ Emperor XLII ! , , :

dir | OutFile -Encoding UTF8 test 

, Vim . , OEM, ASCII , .

:he 'fileencodings' - , , @ Dan Fitch, , Win7.

+5
4

Windows UTF-16 Unicode, , UTF-16, vim 8- (, latin1).

:set encoding=utf-16 vim .

+4

. cmd ( Console2) , :

prompt> myBatFile.bat > myOutputFile.log

^@, , :

:s/\r\(\n\)/\1/g

, ( , , unix Dos- ). , PowerShell, Windows 7. , ^@, ^M ÿþ ( , , gVIM ).

, , bat, PowerShell gVIM:

prompt> myBatFile.bat | Out-File myOutputFile.log -encoding UTF8

, .

+3

powershell

set-content c:\file.txt -encoding Unicode # or BigEndianUnicode

out-file

+1

Powershell. vim, .

Look at :he fileencodings(pay attention to trailing files) - this option allows you to choose which encodings vim will do. By default, Vim 7.x will use ucs-bomand try to decode the byte order mark, but yours vimrcmay set a different list; make sure it doesn't start with something like latin1. By default, on my x64 Windows 7 machine, the output of the Powershell command passed to the file reads vim just fine.

Any setting fileencodings- ucs-bomor utf-16should fix your problem.

+1
source

All Articles