How can I force Emacs to use tab button and TAB character in "normal stupid way"[1], like in nano or VScode or JetBrain's IDEs. All I can find is smart-tabs package and indent-tabs-mode, but that not what I looking for. At this moment I am using [source]

(setq-default indent-tabs-mode t)
(setq backward-delete-char-untabify-method nil)
(setq indent-tabs-mode t)

(defun my-insert-tab-char ()
  "Insert a tab char. (ASCII 9, \t)"
  (insert "\t"))
(global-set-key (kbd "TAB") 'my-insert-tab-char) ; same as Ctrl+i

But it doesn't feel right, in python code for example, if I press RET after for i in range(10): Emacs will use spaces for indentation instead of tab character. So is there simpler way to do it? Also I will grateful if you suggest me some package for auto replacement spaces with tabs[2] and visualize them like | symbol.

P.S. I use Doom Emacs 26.3


[1] When I press TAB I want Emacs to insert TAB character (\t). If there are several TABs in text, pressing Backspace I want to delete only one.

[2] Example:

for i in range(10):
....if a == 1:

for i in range(10):
<-->if a == 1:

Where . is space and <--> is TAB character

  • Please clarify what you mean by "normal stupid way" (and be careful to distinguish the TAB key from the TAB characters when you do that). Similarly, explain what you mean by "auto replacement spaces with tabs" and by the "them" that follows. – Stefan Aug 5 '20 at 15:51
  • Here's what I do: github.com/malb/emacs.d/blob/master/malb.org#tab-dwim which may or may not be what you want. – Martin R. Albrecht Aug 5 '20 at 20:05

Your Answer

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

Browse other questions tagged or ask your own question.