Notepad++: cursor past end of line / virtual spaces?

11

8

TL;DR - How can I enable virtual spaces to move the cursor past the end of a line of text?

Long version - In Notepad++, when trying to select (using the mouse) a long line of text that extends past the right edge of the window, causing it to scroll horizontally, my mouse will sometimes go slightly up or down enough to move the cursor to the adjacent (usually much shorter) line, causing the cursor to snap back to the left where that adjacent line ends; which in turn scrolls the window horizontally back to the left, making it difficult to quickly readjust and finish dragging out my selection.

Some (though woefully few) text editors have an option for "virtual spaces", or cursoring past the EOL, to make it much easier to mouse/arrow around without being restricted to existing text/whitespace.

How can I make this happen in Notepad++ (without hacking the source myself)?

acatalept

Posted 2012-03-16T17:44:39.450

Reputation: 596

1start of line, hold SHIFT + END, have the whole line selected? I know it's not the same as what you wanted, but it's what I do. – Rob – 2012-03-16T17:50:45.047

1Not what you ask, but the problem would go away with line wrapping. – Eroen – 2012-03-16T17:55:30.390

@Rob: This is generally an issue when I'm trying to select a specific long chunk of a very long line of code, but that line is intermingled with other much shorter lines. I could also use SHIFT + CTRL + RIGHTARROW to quickly select rightward from my starting point one word at a time, Notepad++ is pretty good at detecting word-break characters such as periods, parentheses, etc. when there aren't any actual spaces separating words (such as in a long object reference) e.g. (javascript): someObjectName.subObject.property['index'](parameter) – acatalept – 2012-03-16T18:00:37.310

@Eroen: glad you suggested this, I haven't used word-wrap in N++ for a long time, as it used to bring the program to its knees with large files... but it actually works very nicely even for my bigger 20k line files, and even lines up indents on wrapped lines ;) – acatalept – 2012-03-16T18:05:52.700

Answers

14

Sort of a hack (sends a window message directly to the Scintilla edit control on startup), but works great:

  1. Install NppExec plugin

  2. Go to Plugins -> NppExec -> Execute

  3. Enter the following code:

    // ensure console stays hidden
    NPP_CONSOLE 0
    
    // enable virtual spaces (cursor past end of line) outside column edit mode
    SCI_SENDMSG 2596 3 0
    
    // SCI_SENDMSG == send message to Scintilla edit control
    // 2596 == the message we're sending is SCI_SETVIRTUALSPACEOPTIONS
    // 3 == send the value (SCVS_RECTANGULARSELECTION | SCVS_USERACCESSIBLE)
    // the default value is 1 (just SCVS_RECTANGULARSELECTION) for
    //   virtual spaces in column select mode only
    // you can find these values by poking around the source code a bit, or
    // see http://www.scintilla.org/ScintillaDoc.html
    
  4. Click the Save button at the bottom, and give the script a name

  5. Now go to Plugins -> NppExec -> Advanced Options

  6. On the right, under "Execute this script when Notepad++ starts", select the script name you just saved

  7. Click OK, close/reopen Notepad++, and enjoy ;)

acatalept

Posted 2012-03-16T17:44:39.450

Reputation: 596

where are message codes like 2596 documented for other scintilla commands? poking Scintilla.h only? currently at http://tortoisesvn.googlecode.com/svn/trunk/ext/scintilla/include/Scintilla.h ?

– n611x007 – 2012-12-21T08:07:36.100

What is 0 in SCI_SENDMSG 2596 3 0 ? – n611x007 – 2012-12-21T08:10:58.007

@naxa: see the Scintilla documentation for the message codes, e.g. http://www.scintilla.org/ScintillaDoc.html#SCI_SETVIRTUALSPACEOPTIONS (I believe the 3rd parameter is unused for most of these, but must be set to 0 rather than omitted)

– acatalept – 2012-12-21T16:29:35.917

"Sort of a hack" - a hack means accessing something that the software was not supposed to do. This looks like a feature to me. – Natalie Adams – 2012-12-21T16:37:56.700

@Nathan: semantics are fun ;) I meant essentially that using the NppExec plugin to send window messages directly to the controls is sort of a hack, not something that Notepad++ was specifically designed to do (aside from thoughtfully providing a plugin framework to grease the wheels) – acatalept – 2012-12-21T16:50:05.457

about the third 0: I came to think that this is the type information for either the single preceding parameter or the return value. I saw an example where this last thing was @"" instead of 0 - I think it meant string. Well, only guessing, haven't found the documentation yet. – n611x007 – 2012-12-21T20:44:16.393

More recent nppExec versions (>0.4.3?) have an experimental-looking feature to look up the function number for you by name, eg. SCI_SENDMSG SCI_POSITIONFROMLINE 83 0 works. – n611x007 – 2012-12-21T20:45:31.840

After a SCI_SENDMSG function call, you can save the return value in the next line with with the $(MSG_RESULT) internal variable. You can use it in other function calls. For example, you can save it in a user variable called result like this: set result ~ $(MSG_RESULT). After saving it, you can use it like this in another function call: SCI_SENDMSG 2142 $(result) 0. – n611x007 – 2012-12-21T20:47:16.553

0

With no admin rights, install NppExec by downloading the dll and installing to npp's plugins o/s directory/folder. Close/reopen npp.

Edit (+2 years): I don't know if this has changed but we now (if not originally) put the NppExec folder into npp's plugins folder - with the dll in the NppExec sub-folder.

Also make sure versions match (remind yourself whether you're on 32bit or 64), and if you have a recent version (2019), you might need the _PA version of NppExec.

Why am I unable to install the NppExec plugin for Notepad++?

Cloink

Posted 2012-03-16T17:44:39.450

Reputation: 1

Something has changed in Notepad++. The Execute is not there anymore. Are there corrections to this? – user215779 – 2017-12-06T13:27:20.487