How to get Notepad++ to automatically indent one tab when hitting enter.



  • Hello Notepad++ Forum;

    Question: How can I get Notepad++ to indent one tab or two spaces when I hit the enter key?

    Here is how Notepad++ currently does:

    if (in_array($some_value,$some_arr)){
    // no indent
    }

    Here’s what I would like for it to do:

    if (in_array($some_value,$some_arr)){
    // indent one tab or two spaces
    tab}

    Thank you in advance.

    PN



  • Try Settings–>Preferences–>MISC. and check AutoIndent.

    You might want/need to change Tab Settings in the Preferences dialog box.



  • Jim;

    Thanks for responding to my question. I appreciate the help.

    The AutoIndent was already checked in the Settings–>Preferences–>MISC. dialog box.

    The Settings–>Preferences–>Tab Settings is set at 2 (Default). I can increase it to five and it still won’t indent.

    It looks like it ought to be indenting but it’s not. It could be a bug in the program.

    Are there any other suggestions I might try?

    Thanks.

    PN



  • I believe the functionality you are looking for is controlled by the lexer for the “language” of the file you are editing (e.g. file.c, file.asm, file.cpp).

    It looks like you may be editing PERL. If I edit a .C file, autoindent works as expected, but if I set the Language to PERL, autoindent does not work as I would hope.



  • Jim;

    I’m using PHP. My initial question was not clear. It’s my fault.

    The first line does indent. It’s the second line I am talking about - the one that has the closing bracket.

    // PERL does like this:
    if ($one == NULL){
    }

    // C and PHP both do like this:
    if ($one == NULL){
    –>one tab indent
    } bracket does not indent

    // I’ve been using UltraEdit for 15+ years. It does like this:
    if ($one == NULL){
    –>} bracket one tab indent

    // I’m trying to get Notepad++ to do like this:
    if ($one == NULL){
    –>one bracket first line indent
    –>} bracket one tab indent

    I became accustomed to indenting the bracket one tab or two spaces with UltraEdit.

    The last two upgrades of UltraEdit did not work right for me. That’s when I started using Notepad++.

    Notepad++ is a really nice program. It’s had a lot of thought and hard work go into it.



  • @Pete-Norris I see. I’m pretty certain the lexer for the language (PHP in your case) controls the auto-indent behavior. I don’t think there is any way at run-time to modify its behavior. I assume you’d have to edit the lexer to make it behave differently and then build a custom NPP.

    I am not aware of any, but there may be a plug-in for NPP you could find that handles indentation in some other way.

    Sorry I have no better ideas.


Log in to reply