How do I move bookmarks to a copy of the same file?



  • I have a document with 4987 lines and 62 bookmarks. I made a copy of this file to another hard drive and want to import those bookmarks. The file name, modified date, and creation dates are the same for now. I tried saving the session and editing the session file by copying the marked lines to the new document. That didn’t work. Seems like the only way to do what I want is manually place the bookmarks again which would be very tedious and time consuming.



  • Bookmarks are stored in session file. You can copy session file (which has this bookmark file saved) to other place, edit them and correct path to new localization for this file (filename attribute). After this you can load this new session file.



  • @ArkadiuszMichalski said in How do I move bookmarks to a copy of the same file?:

    Bookmarks are stored in session file. You can copy session file (which has this bookmark file saved) to other place, edit them and correct path to new localization for this file (filename attribute). After this you can load this new session file.
    Didn’t work. I loaded the session file and it did two wrong things:

    • It added double bookmarks to a file that already had bookmarks.
    • It bumped certain bookmarks down multiple lines. They were not on the correct line where I originally placed them.


  • @tehmasterer

    Here’s how I might do it, using the Pythonscript plugin and the following script:

    # -*- coding: utf-8 -*-
    
    from Npp import editor, notepad, NOTIFICATION, SCINTILLANOTIFICATION
    
    NPP_BOOKMARK_MARKER_ID_NUMBER = 24  # from N++ source code: MARK_BOOKMARK = 24;
    NPP_BOOKMARK_MARKER_MASK = 1 << NPP_BOOKMARK_MARKER_ID_NUMBER
    
    if 1:
        line_nbr = editor.markerNext(0, NPP_BOOKMARK_MARKER_MASK)
        bookmark_line_list = []
        while line_nbr != -1:
            bookmark_line_list.append(line_nbr)
            line_nbr = editor.markerNext(line_nbr + 1, NPP_BOOKMARK_MARKER_MASK)
        print(bookmark_line_list)
    else:
        for line_nbr in bookmark_line_list:
            editor.markerAdd(line_nbr, NPP_BOOKMARK_MARKER_ID_NUMBER)
    

    Have both the file with the original bookmarks (call it “B1”) and the file you want to apply the bookmarks to (call it “B2”) open in Notepad++ tabs.

    • Make B1 the active file.
    • Run the script as written above.
    • Change the if 1: line in the script to if 0: and save the script.
    • Make B2 the active file.
    • Run the (modified) script.
    • B2 should now have the same bookmarks as B1.

Log in to reply