How to indent a block of Python code in Notepad++?
Solution 1
Just select the text you want indented and hit Tab. To un-indent, select the text and hit Shift+Tab.
If you're in "Normal text file" mode, this will give you tabs (\t
characters). If, however, you're in Python mode (which you enter either by saving as a .py
file or by selecting Python from the Language menu), it should default to using four spaces instead of tabs. To configure the way tabs work yourself, go to Settings → Preferences → Tab Settings (for Python, this should default to "Tab size: 4" with "Replace by space" checked).
Solution 2
Select all 3 lines and hit the Tab key. To undo this action you can hold down Shift while pressing the Tab key.
Pro Tip: As long as you have at least 2 lines partially selected, you can tab in the entire block.
Example:
If you want to change tab settings there are two locations in Settings -> Preferences
- Under Tab Settings: You can change the tab size and you can check off the Replace by space option if you want NPP to use spaces for tabs.
- Under MISC: you can check-off Auto-indent in case you have that option turned off.
Shashank Sawant
MEMS Engineer | Looking for jobs | Please connect me on my LinkedIn profile esp. if youare in the field of MEMS/Process Engineering (linkedin.com/in/sgsawant)
Updated on August 16, 2020Comments
-
Shashank Sawant over 3 years
While coding in
Matlab
, I had the option of smart indenting my code using the shortcut Ctrl+i. Is there a similar option forPython
usingNotepad++
?Specifically, I am looking for a solution to the following problem:
I want the blockline 1 line 2 line 3
to be converted to
line 1 line 2 line 3
On a side-note, I found this to be surprisingly easy with SE editor (keyboard shortcut: Ctrl+k). I want this feature to be available for other languages as well (in my experience good indentation hasn't killed anyone, regardless of the language).
-
ooga about 10 yearsAnd shift-tab de-indents.
-
ooga about 10 yearsDefinitely change it to spaces! Tabs suck, and they don't seem to display properly on SO.
-
Mr. Polywhirl about 10 yearsI like spaces for Python, but tabs for C and Java. I wish there were profiles that you could set up for the language you are working with.