Notepad++ indentation messes up

63,432

Solution 1

There is no universal tab size, so I always make sure to replace tabs by spaces (so you know what you see is what you get everywhere else as well)

Go to Settings -> "Preferences..." -> Language Menu/Tab Settings and check 'Replace by space'

Solution 2

I would suggest going to View > Show Symbol > Show Whitespace and Tab to get an better idea of how your indentations look.

Solution 3

PEP 8 tells us to use spaces instead of tabs in Python for cross-editor compatibility and consistency:

http://www.python.org/dev/peps/pep-0008/

Have a look at this answer for how to change tabs to spaces in Notepad++

Convert tabs to spaces in Notepad++

Perhaps that will fix your problem

Solution 4

Use Python Indent Plugin for Notepad++: I have used both Pycharm & Notepad++, and frankly - even though both are installed on my machine right now I prefer using Notepad++. So, if you want to continue using Notepad++ for Python development you should definitely install the 'Python Indent' Plugin. This plugin will automatically create tabs for you when writing Python code. The only downside to the plugin is you have to remember to Enable it (by going to Plugins --> Python Indent and then clicking 'Enable') when you want to use it.

To install the Python Indent plugin in Notepad++ just go to 'Plugins' --> 'Plugin Manager' and then click on 'Show Plugin Manager'. Then check off 'Python Indent' and click on the 'Install' button.

Additionally, you should Follow Python's Usage Guide: Tab spacing can differ across programs and, following the recommendations of PEP8 (Python Enhancement Proposals Number 8 - which is Python's Accepted Styling and Usage Guide) you should use the space bar to make your indents. Check out the PEP8 Page about spacing here: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces

Good luck!

Solution 5

Tiny update - to get spaces as tabs, you now go to Settings>>Preferences>>Tab Settings and check the "Replace by space" box

Share:
63,432
iman453
Author by

iman453

Updated on June 26, 2020

Comments

  • iman453
    iman453 almost 4 years

    I'm coding in Python and I really like Notepad++. However, off late when I use tab to indent, it seems fine in Notepad++, but when I run the program I get an indentation error, and when I check my code in Emacs or something, I find that Notepad++ actually adds more tab spaces than it shows on screen. What is happening?

  • Ashley Grenon
    Ashley Grenon almost 14 years
    oh yeah, I forgot to mention that too. One too many times I've got bitten by using the tab. :)
  • iman453
    iman453 almost 14 years
    Oh, sweet..didn't know that was possible. Thanks!
  • iman453
    iman453 almost 14 years
    Thanks townsean. Thats really useful :)
  • danyim
    danyim almost 14 years
    +1 This is exactly what I do before I spend serious development time on any IDE.
  • James
    James about 11 years
    You can make this change for Python only if you select Go to Preferences -> Language Menu/Tab Settings -> <Select Python from the list> and check 'Replace by space'
  • Doogle
    Doogle over 7 years
    Tab is usually 4 spaces by convention. I guess this is intuitive. But in real world Notepad++ has its own way which pythons seems not to understand. Thanks for the fix. This really helped me.
  • Ari
    Ari about 7 years
    Under appreciated comment. This allows for instant correction of faulty tabs/spaces in Notepad++. Thank you
  • Hack-R
    Hack-R almost 7 years
    Any different from selecting python under Tab Settings in that same window?
  • Thomas
    Thomas over 6 years
    I can't understand with Python is so picky between a tab or 4 spaces... why don't they treat them the same way?
  • Pritesh Gohil
    Pritesh Gohil almost 4 years
    I would recommend this solution instead of 'Replace by space'.