FG
💻 Software

emacs: how to indent/unindent region of python code by 4 spaces?

Fresh7 days ago
Mar 15, 202643950 views
Confidence Score1%
1%

Problem

I have a region of python code selected in emacs. What are the most efficient ways to indent and unindent every line in it by 4 spaces? Ideally I'd like something that's not context sensitive (eg. it'll allow me to indent passages within docstrings where the indentation does not relate to python syntax). My mode line shows . Searching the web I found a lot of discussion of using instead of , but I only started using emacs a few days ago so I'm wary of changing defaults before I have had a chance to understand and them. If changing to is the best option I'm happy to accept that as an answer. What I've tried (from the manual): no effect no effect (indent-rigidly) indent every line by one column (and deselects the region) indents one first line by a tab (length of 8 spaces) - "C-M-q is undefined" The only way I've found is using regex-replace, but that's an awful number of keystrokes for such a simple task.

Error Output

(Python)

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: emacs: how to indent/unindent region of python code by 4 spaces?

Low Risk

Assuming that the variable is 4:

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment