How can I set Notepad++ to indent with spaces?

  • I would like Notepad++ to automatically indent using spaces if the previous line is indented using spaces, and with tabs if the previous line is indented using tabs. I know that this can be done by enabling the “Replace tabs with spaces” option, but I wouldn’t like to lose the ability to add tabs when I want to.

  • @Runemoro

    currently, I don’t see that this can be solved by using npp builtin features/settings
    and I’m not aware of a plugin which does this.

    I can think of a python script doing it if you are willing to install python script plugin.
    In case you are - please don’t install the plugin via plugin manager instead use the msi
    package from here.


  • I patched my version of NPP for doing that.
    Here is the patch.
    Here are binaries.

  • There are at least 3 related fixes that I wanted in this area and implemented for myself.

    1. New line will be indented according to the indentation style of previous line.
    2. When a line indent is modified (add/remove tab) the indent will be according to current indent style and not according to global style.
    3. When pressing multiple ENTERs to add blank lines the last line should be indented automatically but blank lines should be empty and not with indent whitespace.

    Can’t tell if everyone will be happy with such behavior but when working with code from multiple sources and attempting to respect each source style current Notepad++ indentation is quite annoying.

  • In old version this function existed.
    Why it doesn’t exist now ?
    How can we do to get 4 spaces when we press the tab ?

  • @Alice-Choury

    your question is different to what the original poster asked for
    but luckily yours can be solved easily by checking
    Replace by space under Settings->Preferences->Language


  • I find it pretty ridiculous that this isn’t a default behavior. If I select multiple lines of text, it is not unreasonable to expect that they will paste in the same relative position to each other.

  • @Christopher-McLaughlin

    not quite sure what you are referring to?


  • Quoted:

    if the previous line is indented using spaces, and with tabs if the previous line is indented using tabs

    I’m curious. Why do you need such a behaviour? You are not editing source code, I guess.

  • @NippurDeLagash
    My reason for needing such behavior is that a source project has many authors. Think of multiple libraries. Coding style is not always strictly enforced (it is a different debate if it should be). And while I may modify any source file during development or debugging it is a good habit that a small fix will respect the original style of the code surrounding it.

Log in to reply