Request about the Auto-indent feature



  • Hello,

    I am writing this because the Auto-indent feature is behaving differently in Notepad++ compared to other editors that have this feature.
    Because of this I keep Auto-indent disabled, even though I would like to have it enabled.

    If you have a line in which the text starts after a number of spaces, the cursor is at the end of that line and you press Enter, then the same number of spaces are automatically added on the new line. This is correct behavior.
    Now if you delete the spaces on the current line and press Enter again, the new line should not have any spaces, but it gets the same indent like the first line above which has some text.
    In other editors that I have used if you press Enter while you are on a blank line, the new line will be blank as well, but not in Notepad++ if there is a line with some indent above.

    I don’t want to have spaces on blank lines, but because of this behavior I have to use the trim trailing space feature quite often if I have Auto-indent enabled.
    Please change this behavior or add an option to customize it.

    Best Regards,
    Cyril



  • This behavior makes me crazy also. I’ve got to believe that this complaint has been registered many times, although I haven’t checked (that’s on me). Everyone has their own priorities on what they work on in their software, and for Notepad++ it is no different. One positive is that the source code is available, so anyone could get in there and find the “problem” and fix it, for just themselves, or to possibly to show the world.



  • Hello Cyril and Scott,

    You can emulate a “hard” Enter, which ALWAYS moves cursor on column 1, very easily :-) This could be a work-around !

    • Open your shortcuts.xml file, with an OTHER editor than Notepad++ ( Microsoft Notepad or Wordpad or any other simple editor … )

    • Depending of your N++ installation, the shortcuts.xml file may be located

      • in the %AppData%\Roaming\Notepad++ folder
      • in the same folder than Notepad++.exe
    • Inside the macro section of shortcuts.xml, just add these five lines, below, which defines a new macro, that I called Cursor at column 1. Of course, you can choose any other text !

        <Macro name="Cursor at column 1" Ctrl="yes" Alt="no" Shift="yes" Key="13">
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />
            <Action type="0" message="2395" wParam="0" lParam="0" sParam="" />
        </Macro>
      

    The value 2395 comes from the Scintilla.h file, found in the archive npp.6.7.9.src.zip, in the folder notepad-plus-plus-master\scintilla\include ( #define SCI_DELLINELEFT 2395 )

    It’s not very difficult to guess what that simple macro does, isn’t it !

    I associated the shortcut CTRL + SHIFT + Enter to that macro, because I think it’s not used on N++ default configuration. Just verify on your own configuration. If necessary, choose the menu option Macro - Modify Shortcut/Delete Macro, to change it.

    Well, now, :

    • Write some spaces or tabulations, followed by any text, in a new tab

    • If you end this text by a hit on the Enter key, you’ll get, as expected, the previous indentation

    • Now type, again, some text and end this line, using the shortcut CTRL + SHIFT + Enter => Your cursor is back to column 1

    • Then, hit, repeatedly, on CTRL + SHIFT + Enter => You still get some pure blank lines

    • And, as soon as you hit the Enter key, ONLY, you’ll obtain, again, the previous indentation !

    Hope it may be useful to someone, anyway !

    Best Regards,

    guy038

    P.S. :

    Very soon, with the Christophe Meriaux’s PullRequest ( see below ), it won’t be necessary to use an other editor to change the shortcuts.xml file. You’ll just change it from inside N++, then stop and restart N++ to get the changes :-)

    https://github.com/notepad-plus-plus/notepad-plus-plus/pull/70



  • It seems to me that the same behavior as guy038’s macro will occur if one uses the “Insert Blank Line Below Current” command (default Ctrl+Alt+Shift+Enter), also found on the Edit -> Line Operations menu.

    Invoking this command creates an empty line below the current line (obviously), but more importantly seems to always leave the caret/cursor in column 1, regardless of the indentation of the line above (the one that the caret was on when this was invoked).

    Thus, no macro needed! Although, holding down all those modifiers is a bit of a challenge…solution: remap to something simpler.



  • Hi Scott,

    Once again, you’re completely right. Although the two functions Insert Blank Line Above/Under Current came with a recent N++ version
    ( v6.4.4 ), I should have looked around the different N++'s features, before posting :-(

    Indeed, your solution behaves exactly like mine. So, my post was, therefore, useless !

    Cheers,

    guy038


Log in to reply