问题
I'm in text mode and want my tab key to indent a line to two spaces.
The file looks like this:
Line one
Line two
The cursor is situated before the 'L' : "Line two", and I hit TAB and it gets indented 6 spaces as opposed to the desired 2 spaces.
Actions I've tried:
I've tried updating the variable:
tab-stop-list
(setq tab-stop-list '(2 4 6 8 10 12 14 16))
I've tried adding a
text-mode-hook
(add-hook 'text-mode-hook '(lambda () (setq tab-width 2)))
回答1:
Add this to your .emacs :
(add-hook 'text-mode-hook
'(lambda ()
(setq indent-tabs-mode nil)
(setq tab-width 2)
(setq indent-line-function (quote insert-tab))))
See Emacs Indentation Tutorial.
回答2:
The default for in text-mode will indent to the first non-whitespace character in the line above it.
From the key binding documentation in text mode
TAB (translated from ) runs the command indent-for-tab-command, which is an interactive compiled Lisp function in `indent.el'.
It is bound to TAB.
(indent-for-tab-command &optional ARG)
Indent line or region in proper way for current major mode or insert a tab. Depending on `tab-always-indent', either insert a tab or indent.
In most major modes, if point was in the current line's indentation, it is moved to the first non-whitespace character after indenting; otherwise it stays at the same position in the text....
Luckily, this can be changed. Adding the following to your text-mode-hook should do what you need:
(setq tab-width 2)
(setq indent-line-function (quote insert-tab))
回答3:
Try setting
(setq standard-indent 2)
In your .emacs
来源:https://stackoverflow.com/questions/3976240/how-to-change-indentation-in-text-mode-for-emacs