Moving And Selecting Around

From Notepad++ Wiki
(Redirected from Selection)
Jump to: navigation, search
Commands for navigation and text selection

Notepad++ inherits from the rich collection of commands the Scintilla component exposes in order to move the cursor, current line, or both around, and for making these moves extend the selection. Not all of them are mapped to key combinations, because the obvious available ones are simply too few. This page will review the available commands, how they are named in the Shortcut Mapper, and how to trigger them from the keyboard by default.

Absolute moves

Basic cursor moves
SCI_LINEUP Move cursor up one line Up Arrow
SCI_LINEDOWN Moves the cursor down one line Down arrow
SCI_CHARLEFT Moves cursor to previous position Left arrow
SCI_CHARRIGHT Moves cursor to next position Right arrow

Can you think of reasons to remap them? A prank, perhaps. Or a broken keyboard.

Moving on the same line

There are many shades of it. For instance, what does "moving to the beginning of the line" mean?

  • Moving to the first character?
  • Moving to the first visible character?
  • Moving to the first non-whitespace character?
  • Moving to the first character of the current subline (an offshoot from a long wrapped line)?

and so on. There are Scintilla commands for everything in this respect.

Same line cursor moves (but what "line" means may vary)
SCI_WORDLEFT Move to next word start on the left Ctrl+Left arrow
SCI_WORDRIGHT Move to next word start on the right Ctrl+Right arrow
SCI_WORDLEFTEND Move to next end of word on the left None
SCI_WORDRIGHTEND Move to next end of word on the right None
SCI_WORDPARTLEFT Move to the next capitalisation change on the left Ctrl+/
SCI_HOME Move to column 1 of the line None
SCI_HOMEDISPLAY Move cursor to first visible character Alt+Home
SCI_HOMEWRAP Move to column 1 on the current line, even if it is a wrap offshoot None
SCI_VCHOME Goes to the first non whitespace of the line. If it was there already, move to first character of line None
SCI_VCHOMEWRAP Same, but "line" can be a sub-line from a wrapped document line Home
SCI_LINEEND Move to last character of the line None
SCI_LINEEENDDISPLAY Move cursor to last visible character Alt+End
SCI_LINEENDWRAP Move to last character on the current line, even if it is a wrap offshoot End

By the way, a word is a maximal contiguous sequence of word characters on the same line. What are word characters then? You would expect this to include all lowercase and uppercase Latin-1 letters, digits and underscores. It does, but has to consider accented letters and underscores. For non-Western languages, the definition will be somewhat different. That definition can be made dynamically using a macro.

As expected, an underscore or digit is considered to be a capitalisation change. However, a digit and an underscore are assumed to be of the same capitalisation kind, presumably of type "other" as opposed to "lowercase" or uppercase".

The / in the above default shortcuts must be the one on the main keyboard; Numpad / is different. If / is a shifted key, that key will work, so on some European keyboards, you get Ctrl+(Shift+)/ by hitting Ctrl+(Shift+):. However, when \ is gotten through AltGr-8, the Ctrl-\ shortcut is out of reach and must be remapped.

Moving further up or down

Changing the current line
SCI_PAGEDOWN Go forth one page PageDown
SCI_PAGEUP Go back one page PageUp
SCI_STUTTEREDPAGEDOWN Move to last line of display None
SCI_STUTTEREDPAGEUP Move to top line of display None
SCI_PARADOWN Move to previous start of paragraph Ctrl+]
SCI_PARADOWN Move to next start of paragraph Ctrl-[
SCI_DOCUMENTEND Move to last line of document Ctrl+End
SCI_DOCUMENTSTART Move to first line of document Ctrl+Home
Search -> Go to line Goes to either a specified line or position in the dialog it pops up. Double-clicking the location part on the Status bar also works. None
Search -> Next bookmark Move to the next Line bookmark F2
Search -> Previous bookmark Move to the previous Line bookmark Shift+F2
Search -> Jump Up -> n-th style Move to the previous word marked using the n-th style Ctrl+Shift+n
Search -> Jump Down -> n-th style Move to the next word marked using the n-th style Ctrl+n

For the Jump Up and Jump Down commands, the default Find style can be used as well, in which case n is 0. Otherwise it ranges from 1 to 5.

A paragraph starts at a non-empty line which follows an empty line (or is the first line in document).

Note that the Change Markers plugin enables one to jump from changed line to changed line, with a distinction being made between saved and unsaved changes.

Starting a selection

To start a selection, you can simply use commands that extend the selection (see next sections) starting from the current caret position. However, a number of mouse actions may simplify or enrich this staple feature:

  • Clicking an unselected place cancels all selections.
  • Clicking on a margin that reacts to mouse clicks, typically all but the fold and bookmark margins, selects the whole line at the same horizontal position.
  • Triple-clicking on a line selects it all.
  • Double-clicking a word will select it, and possibly trigger Smart Highlighting if enabled.
  • Ctrl-double clicking on some text finds the surrounding token delimiters (by default, '(' and ')') and highlights the whole text in between. Escaped parenthess are taken as delimiters. However, if " is chosen as delimier both sides, escaped double quotes are ignored. Multi-line selections are allowed optionally, and not by default.Change the deliiters from Settings -> Preferences -> Delimiter.
  • Search -> Select All Between Matching Braces is active when caret is on a brace, and performs the selection including both braces. A companion command is Search -> Go to Matching Brace.
  • Shift+clicking some place extends the active stream selection up to that point. If the current selection is a rectangle, it will add a stream selection to the rectangle area.
  • Crl+clicking somewhere will start a new selection there. If the current selection is not a rectangle, this will not cancel the previous selection(s), while a simple click would.
  • Alt+clicking somewhere starts a rectangular selection, cancelling any existing selection.
  • Using Edit -> Begin/End Select will mark (but not visually) the starting point of a selection. The menu entry gets checked when you do. When you hit this menu item again, all text between current position and memorised position is selected - the caret is at the end position.

When multiple selections are cut or copied to the clipboard, their text is plainly concatenated from the top of document to the bottom, without an intervening separator.

Typing into one of multiple selections causes the typed text to replace each elementary selection. This feature is called Multi-Editing.

The main actions starting a rectangular selection are summarised in a small dialog box summoned by Edit -> Column Mode....

Extending stream selection

It is very common to associate to a cursor move a selection-extending move. Add "EXTEND" to any move command to get the comand that moves with selection extension. Thus SCI_VCHOME becomes SCI_VCHOMEEXTEND.

When defining or remapping cursor moves, it is expected that the associated selection extension command has the same shortcut with the Shift modifier added in. While this consistency rule is not enforced, breaking it could easily confuse users.

Other selection commands

Other selection commands
SCI_SELECTALL Select whole document in stream mode Ctrl+A
SCI_SELECTIONDUPLICATE Inserts a copy of the selection at the caret, the copy becoming the selection Ctrl+D
SCI_SWAPMAINANCHORCARET Toggles caret between start and end of selection None
SCI_ROTATESELECTION Moves the active selection to the next selected range None

Actually, if there is no selection, or if the selection is rectangular, SCI_SELECTIONDUPLICATE duplicates the current line.

In addition, if there is a single stream selection spanning more than one line, the Edit -> Line operations -> Move Up/Down current line commands will move the lines that are part of the selection. Otherwise they just move the current line.

The "next" selection, when using SCI_ROTATESELECTION, is in chronological order, not in text order. However, multiple selections are sent to the clipboard in text order. There is no built-in rotate-back command.

Extending a rectangular selection

The rule is as simple as above, except that the suffix becomes "RECTEXTEND". Thus SCI_LINEDOWN becomes SCI_LINEDOWNRECTEXTEND. However, this doesn't work for all move commands. Here is the list of the commands that extend a rectangular selection:


The expected shortcut for such a message is formed from the base move with the Alt and Shift modifiers added. For example, SCI_PAGEDOWNRECTEXTEND is mapped to Alt+Shift+PageDown.

Changing selection mode

The following synthetic macro changes the mode of an existing selection. Insert this right before the </Macros> tag in shortcuts.xml:

<Macro name="CurrSelMode" Ctrl="yes" Alt="yes" Shift="no" Key="100">
   <Action type="0" message="2422" wParam=mode lParam="0" sParam=""/>

mode is either 0 for stream (default), 1 for rectangular, or 2 for full lines. Who knows, besides being fun, this macro could even be useful.


Scrolling is a quite specific mode of navigation. Contrary to other means, the text you view when scrolling is not the active text, as the caret doesn't move. Nor is the selection affected. Scrolling covers these issues in more detail.

High level viewing

A different way to handle text is having it displayed completely on a dockable window. This is called the Document Map, which is available using View -> Document Map.

Clicking on any point in the Document Map will highlight a pageful of text, centred on the click point, and the active document will be positioned at the top of this page. The highlighting is translucent, which enables accurate yet fast navigation because the syntax highlighting is visible and guides you through the structured document.