How to indent a block of text rightward by 2 whitespace characters in Emacs?
How to indent a block of text rightward by 4 whitespace characters in Emacs?
[EDIT] I need a method that doesn't interfere with CUA mode.
Try the key binding C-x TAB (aka C-x C-i) which is bound to indent-rigidly
, which indents a region by a single space.
So, you'd indent by two by pressing that twice setting the region around the code you want to indent and typing:
C-x C-i C-x C-i
Or, you can pass a numeric prefix with
C-u 2 C-x C-i
To get 4 spaces, do a prefix with 4
C-u 4 C-x C-i
And, as a bonus, you can remove spaces with a negative prefix argument. Removing 4 spaces is accomplished by
C-u - 4 C-x C-i
C-space
, and navigate to the other.
M-x mark-sexp
and M-x mark-defun
.
Commented
Jan 17, 2012 at 15:32
C
-M
-@
3) move cursor to the end of the block 4) C
-X
C
-i
Commented
Jan 17, 2012 at 22:16
You can also use Rectangles.
Mark the beginning of the region with C-Space, go to then end of the region and then type C-xrtRET.
Example:
v----------------------- cursor position
blabla bla bla bla
bla bla bla
bla bla bla
C-SpaceC-nC-n
blabla bla bla bla
bla bla bla
bla bla bla
^----------------------- cursor position
C-xrtM-2RET
blabla bla bla bla
bla bla bla
bla bla bla
^----------------------- cursor position
go to then end of the region
, what concrete keyboard and/or mouse movement do you do? If I use down arrow key to do that, the following C-x
will delete the text.
C-n
. C-space
pushes a mark at the current position and C-n
goes to the next line.
I noticed your edit "I need a method that doesn't interfere with CUA mode." Assuming you have CUA mode enabled, I would also like to recommend you to try C-Enter (cua-set-rectangle-mark). Here is the sequence that works for me.