Community
    • Login

    Make tab key just insert 4 spaces, not insert 4 spaces AND move to the first char on the line

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 4 Posters 1.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alan KilbornA
      Alan Kilborn @VTGroupGitHub
      last edited by

      @VTGroupGitHub

      That’s a very much better description.
      I don’t think there’s a native way to make it do that.
      It does the same thing in the Scintilla demo editor.
      Scintilla is the editing component that Notepad++ embeds.
      It could be a setting in Scintilla that I just don’t know about…

      Michael VincentM 1 Reply Last reply Reply Quote 0
      • VTGroupGitHubV
        VTGroupGitHub
        last edited by

        Thank you for confirming. I just wanted to make sure I wasn’t missing something.

        Michael VincentM 1 Reply Last reply Reply Quote 0
        • Michael VincentM
          Michael Vincent @Alan Kilborn
          last edited by

          @Alan-Kilborn said in Make tab key just insert 4 spaces, not insert 4 spaces AND move to the first char on the line:

          It could be a setting in Scintilla that I just don’t know about…

          Agree the new explanation is much clearer and the setting seems to be:

          SCI_SETTABINDENTS = 0

          By default, N++ has it set to 1. In NppExec, I query it (SCI_GETTABINDENTS ) and it returns 1, but when I set it to 0 and perform the 8 spaces, character at column 9 test described above, I get a tab inserted and my cursor sits at column 4|5.

          SCI_SENDMSG SCI_GETTABINDENTS 
          ================ READY ================
          ECHO $(MSG_RESULT)
          1
          ================ READY ================
          SCI_SENDMSG SCI_SETTABINDENTS 0
          ================ READY ================
          SCI_SENDMSG SCI_GETTABINDENTS
          ================ READY ================
          ECHO $(MSG_RESULT)
          0
          

          Now, assuming the pipe “|” is my cursor:

          |        there are 8 spaces before "there"
          

          Press Tab:

              |        there are 8 spaces before "there"
          

          So a scripting plugin (NppExec, PythonScript, “PerlScript”) could probably do this for you on startup.

          Cheers.

          1 Reply Last reply Reply Quote 3
          • Michael VincentM
            Michael Vincent @VTGroupGitHub
            last edited by

            @VTGroupGitHub
            Sorry, forgot to “@” reference you in my previous reply. Also note Scintilla has the “opposite” behavior for going backwards. That is, when you press backspace it can backspace a single space at a time or backspace an entire tab stop. See the Scintilla Docs for what I mean. I’ve added SCI_SETBACKSPACEUNINDENTS in my NppExec startup.

            Cheers.

            1 Reply Last reply Reply Quote 3
            • VTGroupGitHubV
              VTGroupGitHub
              last edited by

              I hope it’s not too late to say thank you, but I just found your answer to my problem after over a year. Testing with the Console shows your solutions works perfectly, so I’ll set it up now to execute on startup. Thanks!

              1 Reply Last reply Reply Quote 1
              • VTGroupGitHubV
                VTGroupGitHub
                last edited by

                I need to resurrect this issue, as I realized today that the behavior has returned to what it was before my fix two years ago. I assume a recent NPP update changed something, and I need to improve my script. While I dig further, I thought I’d see if anyone knew immediately what needs to be done.

                To summarize, I created the following script and added it to “Execute this script when Notepad++ starts”:

                NPP_CONSOLE 0
                SCI_SENDMSG SCI_SETTABINDENTS 0
                

                This gave me the cursor-movement-after-inserting-a-tab behavior I was looking for. Even though nothing’s changed with my script, or the “Execute…” configuration, the cursor is going to the start of the text today.

                Any help would be much appreciated.

                1 Reply Last reply Reply Quote 2
                • VTGroupGitHubV
                  VTGroupGitHub
                  last edited by

                  A couple of updates. It does work as expected when creating and editing new files. So, the script must be running in that case on startup. And it also works on existing files, IF I manually run the script after opening the file. So the script is still doing the right thing, but something must be “undoing” the setting while opening new files?

                  For now, I’ve added a toolbar button that I’ll use to run the script if I really need this behavior (e.g. editing code), and dig deeper later.

                  PeterJonesP 1 Reply Last reply Reply Quote 0
                  • PeterJonesP
                    PeterJones @VTGroupGitHub
                    last edited by

                    @VTGroupGitHub ,

                    Most likely, Notepad++ has started sending that message to scintilla internally (or is sending it more often than it used to). So you might need to trigger that sendmsg every time a buffer is activated. I don’t think NppExec can register actions on notifications, though I might misremember.

                    If you are willing to switch to PythonScript or similar, they do have the ability to hook notifications (using notepad.callback(my_callback, [NOTIFICATION.BUFFERACTIVATED])), so once you register that notification during the PythonScript startup.py, then it will trigger that action every time you activate a different tab, so that any tab will always have SCI_SETTABINDENTS at 0.

                    VTGroupGitHubV 1 Reply Last reply Reply Quote 1
                    • VTGroupGitHubV
                      VTGroupGitHub @PeterJones
                      last edited by

                      @PeterJones Thank you! I’ll give that a shot and report back when I’m done. I do already have Python Script installed, so hopefully it’ll be fairly straightforward.

                      VTGroupGitHubV 1 Reply Last reply Reply Quote 0
                      • VTGroupGitHubV
                        VTGroupGitHub @VTGroupGitHub
                        last edited by

                        This did work. Thank you again.

                        In case anyone else is interested, I added the following to “C:\Program Files\Notepad++\plugins\PythonScript\scripts\startup.py”:

                        def setTabs(arg):
                            editor.setTabIndents(False)
                        
                        notepad.callback(setTabs, [NOTIFICATION.BUFFERACTIVATED])
                        
                        VTGroupGitHubV 1 Reply Last reply Reply Quote 2
                        • VTGroupGitHubV
                          VTGroupGitHub @VTGroupGitHub
                          last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors