emacs: how to indent/unindent region of python code by 4 spaces?
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Question
01:41 Accepted answer (Score 74)
01:56 Answer 2 (Score 18)
02:27 Answer 3 (Score 10)
02:50 Answer 4 (Score 4)
03:06 Thank you
--
Full question
https://superuser.com/questions/173765/e...
Question links:
[python-mode]: http://sourceforge.net/projects/python-m.../
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#keyboardshortcuts #emacs #python #textediting #indentation
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Question
01:41 Accepted answer (Score 74)
01:56 Answer 2 (Score 18)
02:27 Answer 3 (Score 10)
02:50 Answer 4 (Score 4)
03:06 Thank you
--
Full question
https://superuser.com/questions/173765/e...
Question links:
[python-mode]: http://sourceforge.net/projects/python-m.../
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#keyboardshortcuts #emacs #python #textediting #indentation
#avk47
ACCEPTED ANSWER
Score 76
Assuming that the variable python-indent
is 4:
M-x python-shift-right (C-c >)
M-x python-shift-left (C-c <)
ANSWER 2
Score 19
indent-rigidly
takes a prefix argument indicating how much to indent by, so C-u 42 C-x TAB
indents by 42 columns, and since the default prefix argument is 4, C-u C-x TAB
indents by 4 columns.
If you want to select the region again, do C-x C-x
afterwards.
ANSWER 3
Score 11
Use the indent-rigidly command with a numeric prefix.
C-u 4 M-x indent-rigidly
to indent the region by four spaces, C-u -4 M-x indent-rigidly
to remove four spaces.
ANSWER 4
Score 3
You could also use column mode.
Select the lines in column mode, then add four spaces to all of them at once:
- Jump to column 1 of the first line you want to indent.
C-<space>
to set mark- move the point down to the last lines (stay in column one)
C-x r t
to enter column mode (orC-<RET>
if you've got CUA mode)<space><space><space><space><RET>
You can do a similar maneuver to delete four spaces -- just include 4 columns in your marked region (steps 2-3) and hit <DEL>