Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrease indentation on a couple of lines

Tags:

Is there some way I can mark text in emacs and shift it left (removing starting spaces) by space/Tab granularity?

Same way I would do on some other editor with Shift+Tab.

like image 324
sramij Avatar asked Mar 14 '12 20:03

sramij


2 Answers

  1. Select your region;
  2. Type C-u followed by the number of spaces you want to indent (negative number if you want to decrease indentation);
  3. Use C-x TAB (by default bound to indent-rigidly) to apply the indentation to the region.

This is much more cumbersome than S-TAB, but it is IMHO some kind of last resort in case Emacs formatting doesn't solve your problem.

EDIT: much better solution: Shift a region or line in emacs (accepted answer). This is what I'm currently using in Emacs for changing indentation. WARNING: involves some Emacs Lisp.

like image 184
Miron Brezuleanu Avatar answered Oct 18 '22 22:10

Miron Brezuleanu


This might be simpler and more visually intuitive: first make sure cua-mode is enabled (M-x cua-mode toggles it). Then go to the start of the line and press C-return. A red rectangle appears. Now move your cursor down and right to grow the rectangle as needed. Then press C-d to delete it. That's it.

I come across this problem often when the major-mode doesn't dictate any automatic indentation (or when it messes up).

There is a lot more you can do with cua-mode's rectangles, see http://trey-jackson.blogspot.com/2008/10/emacs-tip-26-cua-mode-specifically.html

like image 35
Joao Tavora Avatar answered Oct 19 '22 00:10

Joao Tavora