Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improved tab in Emacs

I want to override the bad default tabbing scheme in emacs so that it will work like most other editors (eclipse, notepad++). I want to set it so that regardless of mode, tab will insert a tab, and pressing enter will keep me at my current tab depth.

I tried this, but it does nothing:

(global-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq default-tab-width 4) ;; 8 is way too many
like image 443
AlexH Avatar asked Dec 05 '08 20:12

AlexH


People also ask

How do you add tabs in Emacs?

To manually insert a tab in Emacs, use ctrl-Q TAB. control-Q causes the next key to be inserted rather than interpreted as a possible command.

How do I switch tabs in Emacs?

The following commands can be used to switch between tabs: C-x t o. C-TAB. Switch to the next tab ( tab-next ).

How do I disable tabs in Emacs?

If you want to remove tabs in an existing file, mark the whole buffer using C-x h and use M-x untabify .


1 Answers

To make the Enter key take you to the next line and indent it automatically, you can put

(global-set-key (kbd "RET") 'newline-and-indent)

in your .emacs. [Or you can hit C-j instead of Enter.] Once you have that, you'll never need to insert tabs manually, because Emacs automatically indents a new line to extra depth after an opening brace, etc. If you do want to change the indentation, you can hit TAB until it takes you to the right indentation, then start typing from there. [And when you type a closing brace, Emacs is smart enough to take that brace one indentation level backwards.]

You should remove the (global-set-key (kbd "TAB") 'tab-to-tab-stop) for this to work.

like image 76
ShreevatsaR Avatar answered Sep 22 '22 02:09

ShreevatsaR