I would like to have a "Notepad++ shortcut" that will jump to a line in a file

  • Title:
    I would like to have the ability to create a string that Notepad++ recognizes as a clickable link. Clicking on it would take me to the specified line in the specified file.

    Basically, I want the ability to create a specially formatted text string that Notepad++ recognizes as a clickable shortcut. I would imbed this string into a comment. Clicking on it in Notepad++ will take me to the targeted line in the targeted file. If the file isn’t loaded, Notepad++ would load the file, go to the specified line and highlight that line. If the file is already loaded, Notepad++ would switch to that tab and change to the specified line and highlight that line.

    Why do I want this?
    I would like to insert references in my source code to code in other files. In a JavaScript file for example, I would like to put in comments like:

    // Function "editManItem()" is called when a user clicks an "Edit" button from 
    //   inside the HTML table of line items.
    // Works in combination with:
    //    function removeManItem(id)       npp://./s/^function removeManItem/+1
    //    function onEditSet(id)           npp://UserInterface.js/s//+45

    npp://./s/function removeManItem/+1
    Would take me to the current file ("."), do a regex text search for the string “function removeManItem” at the beginning of a line (“s/^function removeManItem/”) then go to next line ("+1").

    Would take me to file “UserInterface.js”, not do any text search search (“s//”) which would place the cursor at the first line of the file, the go 45 lines down ("+45"), essentially going to line #45 of that file.

    Essentially this is a cross-reference capability to source code in another file. It’s dynamic in that it searches based on regular expressions instead of going to a specific line in the file, but (as shown in the 2nd example), it also allows going to specific line numbers.

  • It could be achieved by using a scripting plugin like pythonscript.
    Some simple demo code to show how to get the click notification.

    from Npp import editor, SCINTILLANOTIFICATION
    def goto(args):
        start = editor.wordStartPosition(args['position'], False)
        end = editor.getLineEndPosition(editor.lineFromPosition(args['position']))
        print(editor.getTextRange(start, end))

    but if you want to have this builtin, then you might consider open
    a feature request.

  • @Ekopalypse

    Just a comment. It sure would be idea if the notification itself provided the hotspot text, but sadly, no…

    Your method of getting the text isn’t perfect as I’m sure you know. Maybe a better way would be to find the “bracketing” whitespace around the position, as whitespace definitely seems to break up a url when embedded in a Notepad++ document?

    Also, won’t this script intercept the existing behavior of clicking on http urls?

  • @Alan-Kilborn

    You are right, it is far from solving OPs issue, its purpose was just to demonstrate that it is possible.
    If OP wants to go that way, then I would do more like

    • get line of link
    • parse line to identify which kind of link it is
    • do needed action
      but that would mean, OP needs to define exactly what is required.

    Also, won’t this script intercept the existing behavior of clicking on http urls?

    I don’t think so, it is a notification received by npp and PS independently.

  • Why not just use a cTags plugin? What you’re describing is exactly what cTags does, with out needing to put special formatted strings. You just run cTags on your code to generate a tags file which has all the function definitions and then use the cTags plugin to navigate to them with a shortcut key.

    There is cTagsView, TagLEET, NppGTags.

    I prefer TagLEET and use a modified version of it. cTagsView is “automatic” but only works on the currently viewed file so maybe not what you want. I have not used NppGTags, but others have mentioned it on this site.


  • You can instruct ctags to generate a tag for every file name with –extra=f.
    For TagLEET, with the following text:

    UserInterface.js:45  // any comment you want

    If your caret is in UserInterface.js, Tag Lookup will jump to line 45.
    This feature was intended to copy paste compilation results from terminal and jump to errors and warnings.

    @Michael-Vincent looking at your TagLEET modifications.

  • @gstavi said in I would like to have a "Notepad++ shortcut" that will jump to a line in a file:

    @Michael-Vincent looking at your TagLEET modifications.


    We talked about these a while back over email. I went ahead and tried and got the added column I wanted. Since then I added a few more columns and added autocomplete ability using either the TagLEET pop-up or Notepad++ Scintilla native autocomplete - based on the info in the tag file. I like this feature since it allows me to autocomplete across a bunch of opened files in the same project (they have the same tags file), whereas the plain vanilla Notepad++ autocomplete is only within a single document.