Question

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

Était-ce utile?

La solution

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

Autres conseils

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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top