Community
    • Login

    move to the next _numbered_ line

    Scheduled Pinned Locked Moved General Discussion
    7 Posts 2 Posters 2.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.
    • Nick KatN
      Nick Kat
      last edited by Nick Kat

      Hello!
      As a part of an automatization process I’d like to have a way to move the cursor in Notepad++ down\up to the next\previous numbered line using just a keyboard.
      How would one do that?

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

        @Nick-Kat ,

        Oddly, while the editor component that Notepad++ uses has commands that distinguish between the line-wrapped “line” and the document “line” for HOME and END variants, I don’t think it has those distinguishing versions for LINEUP and LINEDOWN, which you’d really think it would.

        However, a full line-end followed by a right arrow to go to the next character will do what you want (or, at least, what I think you want, or close enough) for going to the next numbered line. And a full-home followed by a left arrow will be at the end of the previous line (and another full-home will take you to the beginning of the previous line). You can make a macro of either of those, and then assign them to a keystroke of your choice.

        If you are in a fresh Notepad++ which hasn’t had any keyboard-shortcut modifications, the following sequence will define those two macros (one for beginning of next line and one for beginning of previous line):

        • Beginning of Next Line
          1. Temporarily get “end of real line” to a shortcut
            • Settings > Shortcut Mapper > Scintilla Commands
            • Filter = SCI_LINEEND
            • click on SCI_LINEEND to select that row
            • Modify
            • choose Ctrl + Alt + End
            • Apply
            • OK
            • CLOSE
          2. Record Macro:
            • Macro > Start Recording
            • Ctrl+Alt+End (this takes you to the end of the current numbered line)
            • Right Arrow (this takes you to the beginning of the next numbered line)
            • Macro > Stop Recording
            • Save Current Recorded Macro
              • Name: Beginning of Next Line
              • Ctrl + Alt + Down
              • OK
          3. Remove temporary shortcut (if you want; or if you like having the full-end, leave it)
            • Settings > Shortcut Mapper > Scintilla Commands
            • Filter = SCI_LINEEND
            • click on SCI_LINEEND to select that row
            • Modify
            • Instead of End in the dropdown, choose None
            • Apply
            • OK
            • CLOSE
        • Beginning of Previous Line
          1. Temporarily get “beginning of real line” to a shortcut
            • Settings > Shortcut Mapper > Scintilla Commands
            • Filter = SCI_HOME
            • click on SCI_HOME to select that row
            • Modify
            • choose Ctrl + Alt + Home
            • Apply
            • OK
            • CLOSE
          2. Record Macro:
            • Macro > Start Recording
            • Ctrl+Alt+Home (this takes you to the beginning of the current numbered line)
            • Left Arrow (this takes you to the end of the previous numbered line)
            • Ctrl+Alt+Home again (to the beginning of the new line)
            • Macro > Stop Recording
            • Save Current Recorded Macro
              • Name: Beginning of Next Line
              • Ctrl + Alt + Up
              • OK
          3. Remove temporary shortcut (if you want; or if you like having the full-home, leave it)
            • Settings > Shortcut Mapper > Scintilla Commands
            • Filter = SCI_HOME
            • click on SCI_HOME to select that row
            • Modify
            • Instead of Home in the dropdown, choose None
            • Apply
            • OK
            • CLOSE

        Now Ctrl+Alt+Down will take you to the beginning of the next numbered line and Ctrl+Alt+Up will take you to the beginning of the previous numbered line. (You only have to go through that whole long sequence one; Notepad++ will save it.)

        Your macros (in %AppData%\Notepad++\shortcuts.xml) will look like the following after you’ve restarted Notepad++ after recording and saving those macros

                <Macro name="Beginning of Next Line" Ctrl="yes" Alt="yes" Shift="no" Key="40">
                    <Action type="0" message="2314" wParam="0" lParam="0" sParam="" />
                    <Action type="0" message="2306" wParam="0" lParam="0" sParam="" />
                </Macro>
                <Macro name="Beginning of Previous Line" Ctrl="yes" Alt="yes" Shift="no" Key="38">
                    <Action type="0" message="2312" wParam="0" lParam="0" sParam="" />
                    <Action type="0" message="2304" wParam="0" lParam="0" sParam="" />
                    <Action type="0" message="2312" wParam="0" lParam="0" sParam="" />
                </Macro>
        
        1 Reply Last reply Reply Quote 5
        • Nick KatN
          Nick Kat
          last edited by

          @PeterJones it’s amazing! I’ve managed to achieve what I was looking for!
          I truly appreciate your help!

          PeterJonesP 1 Reply Last reply Reply Quote 2
          • PeterJonesP
            PeterJones @Nick Kat
            last edited by

            @Nick-Kat ,

            I’m glad it worked for you.

            I was half-afraid you were going to come back and say “if I am on char 120 of line 2 and run the macro you provided, it goes to char 1 of line 3; I want to go to char 120 of line 3, or the last char if there aren’t that many”, and I wasn’t sure how I might go about implementing that without switching from a macro to PythonScript. ;-)

            But since you’re happy, I will pose it as an intellectual exercise for the other regulars in the forum: is there another way, other than Python Script, to extend my macros to work in the “keep the same column when doing the fancy up/down in a visibly-wrapped line” – whether it’s a Scintilla message that I couldn’t find, or a different combination of messages for the macro. Because I really would have though Scintilla would provide the equivalent of the normal up/down behavior for a wrapped line.

            Nick KatN 1 Reply Last reply Reply Quote 1
            • Nick KatN
              Nick Kat @PeterJones
              last edited by

              @PeterJones just maybe one more thing
              Ctrl+Alt+End takes the cursor to the end on the current numbered line, Ctrl+Alt+Home to the start of the current numbered line
              Is there a way to make Notepad++ select text while jumping around?
              I tried holding Shift key but that didn’t work

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

                @Nick-Kat ,

                The “Scintilla” component of Notepad++ (which is what’s doing the underlying editing) has way more actions than you have key-combos available for mapping. Just like the examples I showed above made you actually do a map to get the SCI_LINEEND to Ctrl+Alt+End, you would also have to map SCI_LINEENDEXTEND to Ctrl+Alt+Shift+End if you want the “extend the selection” version of that “END” action. Similarly, if SCI_HOME is mapped to Ctrl+Alt+Home, you would also have to map SCI_HOMEEXTEND to Ctrl+Alt+Shift+Home in order to get the “extend the selection” version of that “HOME” action.

                And if you want to use them in combination to create a macro similar to the ones I made above, you would have to make a separate macro using those new keystrokes, and assign them to the Ctrl+Alt+Shift+Up/Down keystrokes.

                Shift doesn’t magically extend selection with whatever you are doing; what really happens is that Shift triggers a different keystroke mapping’s action, so if you have some action mapped to that key-combo that includes Shift, then that action is what will fire.

                But always, using the Edit > Begin/End Select (or its keyboard equivalent) before a set of complicated caret movements, followed by Edit > Begin/End Select at the end of the set of complicated movements, will then select everything between the two ends of those caret movements. So you could use that if you don’t want to have to manually define shift-versions of a bunch of things.

                Nick KatN 1 Reply Last reply Reply Quote 1
                • Nick KatN
                  Nick Kat @PeterJones
                  last edited by Nick Kat

                  @PeterJones awesome! You are the best!! Thank you!!!

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