56

I have tried to parse a file language_data.txt, which is edited by Emacs. The different columns are separated by tab characters.

But when I opened the file, I found that each of the tab characters had been replaced by many space characters. For example:

en_US   shiphrah        02005   book reader no connection
en_US   shiphrah        02006   user reader no connection

How to insert a tab character in Text mode?

Glorfindel
  • 4,158
Chen Yu
  • 735

4 Answers4

85

C-q <tab>

C-q insert the next character as a raw character

4

In addition to answer given: Check value of indent-tabs-mode, customize it if needed. Several hooks use it's value doing translations TAB-Blank.

4

If you want TAB key to insert a tab character, add this to your ~/.emacs

(global-set-key (kbd "TAB") 'self-insert-command);

More helpful info on emacs + TAB : https://web.archive.org/web/20160312104535/http://vserver1.cscs.lsa.umich.edu/~rlr/Misc/emacs_tabs.htm

ACyclic
  • 1,003
1

Addition to @Vash2593 answer.

If you want to insert tab to more than one line. You can use indent-rigidly which is bound to C-x TAB. Then you can move the indentation interactively with S-left or S-right.

Or you can supply with emacs universal argument C-u. e.g C-u 4 C-x TAB to add 4 spaces. C-u -4 C-x TAB to remove 4 spaces.

This is very handy when it comes to formatting codes in social forums. Which need 4 spaces indent.

azzamsa
  • 131