The other day, I was studying about the Linux du command when I stumbled upon its --files0-from option that enables the tool to accept input file/directory names written in a file. The option has an associated condition that names specified in the file should be NUL terminated.

Now, it was when I started entering names in a newly-created file through VIM, I realized that I don't know how to enter the NUL character while inside the editor window. So I researched a bit, and gladly, found the solution.

So here's how you do this:

Firstly, bring the cursor exactly at the point inside the Vim editor window where you want to enter the control character. Then, press ctrl+v, which tells the editor to insert the next character literally. Now, just type the control character - for example, ctrl+shift+2 in our case produced the ^@ character which is treated as NUL.


That's it. And just in case you want the cat command to print these kind of characters present in a file, use the -v option.

cat -v [file-name]


To access more such Vim-related tips here at FAQForge, check out our Linux&Unix section.

How to insert control characters in Vim (and have them printed through cat)

One thought on “How to insert control characters in Vim (and have them printed through cat)

  • Avatar
    August 1, 2017 at 8:33 am

    Hi there!

    In my case CentOS 7.3.1611 and vim 7.4.160, I have to put the cursor where I want to put the NULL character, then press Ctrl + V folowed by Ctrl + 2 (Without shift).

    Thanks for the post!


Leave a Reply

Your email address will not be published. Required fields are marked *