move to the next _numbered_ line
-
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? -
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
- 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
- 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
- Name:
- 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, chooseNone
- Apply
- OK
- CLOSE
- Temporarily get “end of real line” to a shortcut
- Beginning of Previous Line
- 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
- 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
- Name:
- 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, chooseNone
- Apply
- OK
- CLOSE
- Temporarily get “beginning of real line” to a shortcut
Now
Ctrl+Alt+Down
will take you to the beginning of the next numbered line andCtrl+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>
- Beginning of Next Line
-
@PeterJones it’s amazing! I’ve managed to achieve what I was looking for!
I truly appreciate your help! -
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.
-
@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 -
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 toCtrl+Alt+Shift+End
if you want the “extend the selection” version of that “END” action. Similarly, if SCI_HOME is mapped toCtrl+Alt+Home
, you would also have to map SCI_HOMEEXTEND toCtrl+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 thatShift
triggers a different keystroke mapping’s action, so if you have some action mapped to that key-combo that includesShift
, 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.
-
@PeterJones awesome! You are the best!! Thank you!!!