I want to indent and entire region n spaces to the right or left. I can do this in some modes with C-c > and C-c <, but I'd like to do this in general.
If I need to change my .emacs in order to make this efficient (with a keyboard shortcut like that above) that's fine.
Select multiply lines, then type C-u 8 C-x Tab , it will indent the region by 8 spaces.
Just change the value of indent-line-function to the insert-tab function and configure tab insertion as 4 spaces.
This is because standard tabs are set to eight spaces. Tabs are special characters.
What works for me is: select region and then C-u <number of spaces> C-x TAB
Update
@Eric We could define a function and bind to a keyboard short cut, e.g. C-x C-TAB
. Try adding this to your emacs config.
(defun insert-tabs (n) "Inserts N number of tabs" (interactive "nNumber of tabs: ") (dotimes (i n) (indent-for-tab-command))) (global-set-key [?\C-x \C-tab] 'insert-tabs)
The key part of Sandro's answer is the call to indent-rigidly
.
C-x TAB (translated from C-x <tab>) runs the command indent-rigidly, which is an interactive compiled Lisp function in `indent.el'. It is bound to C-x TAB. (indent-rigidly start end arg) Indent all lines starting in the region sideways by arg columns. Called from a program, takes three arguments, start, end and arg. You can remove all indentation from a region by giving a large negative arg.
So, mark region, enter numeric arg, press C-x TAB
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With