55

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?

4 Answers 4

84

C-q <tab>

C-q insert the next character as a raw character

1
  • 3
    C-q is bound by default to the function quoted-insert, so more specifically, this is M-x quoted-insert <tab>
    – slacy
    Aug 24, 2018 at 16:42
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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.