6

While coding in Matlab, I had the option of smart indenting my code using the shortcut Ctrl+i. Is there a similar option for Python using Notepad++?

Specifically, I am looking for a solution to the following problem:
I want the block

line 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).

3
  • 2
    Select all 3 lines and hit the TAB key... Commented Apr 26, 2014 at 1:40
  • Could you post that as an answer? I will accept it soon. I was not able to find this solution using Google. I am looking for a different solution as well. Your solution adds tabs. Ideally I am looking for a solution that will add 4 spaces. But this works great! Commented Apr 26, 2014 at 1:43
  • related: Automatic indentation for Python in Notepad++ Commented Apr 26, 2014 at 1:48

2 Answers 2

11

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Definitely change it to spaces! Tabs suck, and they don't seem to display properly on SO.
I 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.
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:

enter image description here

If you want to change tab settings there are two locations in Settings -> Preferences

  1. 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.
  2. Under MISC: you can check-off Auto-indent in case you have that option turned off.

1 Comment

And shift-tab de-indents.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.