What you are looking at in Vim are "null" bytes, i.e. bytes with the numeric value zero.
You can check that by putting the cursor on top of that ^@
and typing ga
. This displays the numeric value of the character under the cursor.
If you need to remove all occurrences of that character from a file, you can use sed
, and you don't need to type ^@
for that at all, since sed
(at least the GNU version, not the BSD one it seems...) supports a different notation for hex values:
sed "s/\x00//g" file.txt
That would print the contents of file.txt
to stdout, all zero bytes removed. If you want to remove the bytes in-place (be careful, dangerous to your orignial file, and also (1)!), use the -i
option:
sed -i "s/\x00//g" file.txt
(1) Check the answer by gniourf_gniourf (and the comments) on the caveats re sed
: You will lose the file creation date, and you need to be sure it's really a file you're working on, not a symlink.
For completeness, you can of course remove zero bytes without leaving Vim.
:%s/<ctrl-v>x00//g
:
command mode
%
range: complete file
s/
search
<ctrl-v>
verbatim
x
hexadecimal
00
zero
/
replace with...
/
...nothing
g
globally (multiple times per line)
All this is of course assuming that you are not looking at an UTF-16 file and just being confused by the zero bytes in there. If that's the case, @IgnacioVazquez-Abrams hint at iconv is of course the better way: iconv -f UTF-16 -t UTF-8 file.txt
. But then, Vim shouldn't be showing you ^@
in the first place.