what's the meaning of ^@, ^I and $ in vi?

4

1

When I try to use Context.write(k,v) in MapReduce(using Java) to write data to a file ,I find the following contents in file(opened with vi, have :set list):

^@R^@u^@n^@^I1$
^@a^@c^@c^@e^@s^@s^@^I1$
^@d^@e^@f^@a^@u^@l^@t^@ 2$
^@o^@u^@t^@^I2$
^@p^@r^@o^@j^@e^@c^@t^@^I1$
^@t^@a^@s^@k^@^I1$
^@w^@i^@n^@d^@o^@w^@s^@^I1$
^@y^@o^@u^@r^@^I1$

What's the meaning of ^@ ^I and $? Does ^I mean \t? I know that $ means the end of the line, but does it mean the enter key, just like \n? If so, what's the difference between '$' and '^M' in vi?

Searene

Posted 2013-12-10T15:36:23.040

Reputation: 493

Answers

3

$ is the end of line as displayed by :set list with the default value of the listchar option. ^I is the tab character.

^@ is the null character.

For some weird reason every meaningful character in your file is prepended with a null character except digits and (probably) spaces.

This is not a Vi(m) problem: check the documentation of that method to see if there's a way to output your data without those nulls.

romainl

Posted 2013-12-10T15:36:23.040

Reputation: 19 227

1

The file that you opened is UTF-16 or UCS-2 encoded, which is the standard in Java. vi (as in real vi, not vim symlinked to vi) can only handle ASCII (or ISO-8859-1?) text. Use vim, or convert the file to ASCII (e.g., iconv -f utf-16 -t ascii <input> <output>).

pilona

Posted 2013-12-10T15:36:23.040

Reputation: 1 173

0

If that's Vim behind your vi command, you can reload the file with

:edit ++enc=ucs-2

or directly specify the encoding

$ vim ++enc=ucs-2 filename

or, if you need to open these files frequently, prepend ucs-2 to the 'fileencodings' option, e.g. in your ~/.vimrc.

Ingo Karkat

Posted 2013-12-10T15:36:23.040

Reputation: 19 513

Shouldn't vim automatically detect the encoding? Or does it only do that when there's a BOM? – pilona – 2013-12-11T02:43:54.813

@pilona: What gets detected is controlled by the 'fileencodings' option that I've mentioned. – Ingo Karkat – 2013-12-11T07:58:52.270