Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

^@ symbol in vim

Tags:

vim

file-io

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?
like image 289
JamesWebbTelescopeAlien Avatar asked Feb 03 '12 06:02

JamesWebbTelescopeAlien


People also ask

How do I type special characters in Vim?

While in insert mode, you can insert special characters in Vim by pressing <ctrl-k> followed by a two-character lookup code. For example, <ctrl-k> ? 2 will insert the approximately equal symbol: ≈ .

What does S do in Vim?

Descriptions. s (substitute) will delete the current character and place the user in insert mode with the cursor between the two surrounding characters. 3s , for example, will delete the next three characters and place the user in insert mode. c (change) takes a vi/vim motion (such as w , j , b , etc.).

What is Ctrl Z in Vim?

on linux, CTRL-Z in vi/vim/gvim mean escape to the console, or put this in the background. you then do whatever you want on the console and type fg (foreground) to bring you back into vim edit session.


2 Answers

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.

like image 84
voithos Avatar answered Oct 02 '22 04:10

voithos


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 the 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

like image 26
Coffee and Code Avatar answered Oct 02 '22 04:10

Coffee and Code