NP Rooski  Z
NP Rooski Z

Reputation: 3657

^@ symbol in vim

The following symbol shows up when i view my file in vim.

---<snip>----
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@fstalone
---<snip>-----

The file that I create is by redirecting stdout and stderr of my utility, like this: #./my_util > util.log 2>&1. This file tend to grow quite huge ( ~4 MB )

  1. What is this symbol?
  2. How to get rid of it?

Upvotes: 32

Views: 31979

Answers (3)

Coffee and Code
Coffee and Code

Reputation: 1033

None of the above worked for me. I had a file with '^@' at the end of some lines that I wanted to replace. I managed to substitute it by searching for '[\x0]' using:

%s/[\x0]//g

I hope it saves someone an hour of their life. There's an explanation here that I will go back to read when I'm not so busy: A discussion with a better explanation

Upvotes: 11

Sunil Kumar B M
Sunil Kumar B M

Reputation: 2795

^@ shows up when you try to open a non text file in vim. For example if you open a exe file or an image file ^@ is shown which is a non-readable character. Try opening the file in some other editor and see the result

Upvotes: -7

voithos
voithos

Reputation: 70552

That is the null character, in a format (which Vim uses a lot, as you've probably noticed) called caret notation. Basically, somehow you're getting bytes full of zeros into your file.

Since we don't know what your utility is doing, if it's the culprit, you'll need to show us some code if you want us to help. Otherwise, if you just want to remove the characters from your file, use a substitution:

%s/<Ctrl-V><Ctrl-J>//g

Ctrl-V marks the beginning of an escape sequence. After pressing Ctrl-J as well, you should see ^@ appear in your command. Thus, as you guessed, Ctrl-V, Ctrl-J is one escape sequence for the null character.

Upvotes: 46

Related Questions