Categories
DailyOps

How to insert control characters inside text terminal

Insert control characters inside a text terminal to enhance your personal notes or improve shell one-liners.

Press CTRL+v to insert next character into terminal.

$ bind -q quoted-insert
quoted-insert can be invoked via "\C-q", "\C-v", "\e[2~".

For example press CTRL+v TAB or CTRL+v CTRL+i to insert horizontal tab (see additional notes for reference).

Other useful example is to insert a newline character using CTRL+v CTRL+j or CTRL+v CTRL+l and CTRL+v CTRL+m.


It can be also used to control text formatting.

Key presses used to write the following text:
CTRL+v ESC [ 3 1 m W a r n i n g CTRL+v ESC [ 0 m

$ echo "^[[31mWarning^[[0m"
Warning

You can use these characters inside text files.

$ cat --show-all readme.txt 
^[[34mReadme^[[0m$
$
"Be curious, not judgmental." Walt Whitman^MThere is a hidden message here. Can you read it?$
$ less --quit-if-one-screen readme.txt
ESC[34mReadmeESC[0m

"Be curious, not judgmental." Walt Whitman^MThere is a hidden message here. Can you read it?

As you can see I have used carriage return character to overwrite part of the text.

$ cat readme.txt 
Readme

There is a hidden message here. Can you read it?

Do not copy these examples, you need to use mentioned control codes.

Additional notes

ASCII control code chart

Bash tips: Colors and formatting (ANSI/VT100 Control sequences)