Community
    • Login

    Insert multiple lines of code before or after a specific place in code

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 637 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Rowlfi_the_dogR
      Rowlfi_the_dog
      last edited by

      Hello,

      an absolute newbie in this forum (and to notepad++) needs your help !!

      How could I insert a block of code (a multiple of different lines) at a certain location in the code, which I can indentify and mark with a bookmark ?
      So the bookmarked line would be the one, after (or before) I want to insert several lines of code …

      How could that be done ?

      Thank you, Rowlfi

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Rowlfi_the_dog
        last edited by

        @Rowlfi_the_dog ,

        If I understand your problem correctly, I don’t think it can be done natively in Notepad++ in one step. And bookmarking the active line is not a command that can be recorded in a macro – however, it can be run in a manually-edited macro.

        So if you go to %AppData%\Notepad++\shortcuts.xml and go to the line before </Macros> end-tag, you can insert

                <Macro name="BookmarkAndPaste" Ctrl="no" Alt="no" Shift="no" Key="0">
                    <Action type="2" message="0" wParam="43005" lParam="0" sParam="" />
                    <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
                </Macro>
        

        Save shortcuts.xml and exit/restart Notepad++: you will now have BookmarkAndPaste available in your Macro menu.

        If you copy some text, move somewhere else, and then run that macro (either from the menu, or if you use Shortcut Mapper to assign a keyboard shortcut), then it will automatically bookmark the line where your caret (aka, “typing cursor”) is located, and paste the clipboard contents starting at that caret.

        But your phrasing is a bit confusing. So maybe you really don’t need the “bookmark” feature, per se, and you really just wanted the ability to put a snippet of code at the current caret / typing cursor. In which case, the QuickText plugin or Snippets plugin might be what you want (depending on your preferred user interface). But, as far as I know, neither of those plugins will create a bookmark when you do an insert, so if you really want both features, that won’t necessarily help you.

        Rowlfi_the_dogR 1 Reply Last reply Reply Quote 2
        • Rowlfi_the_dogR
          Rowlfi_the_dog @PeterJones
          last edited by

          @PeterJones

          thank you for your answer !!

          But what you have posted is a bit beyond my notepad++ skills …
          (Remember: I am a notepad++ newbie …)
          I will first have to get a little more aquainted with these options you suggest !
          That will take time.

          I will come back once I have further questions !

          Regards,
          Rowlfi

          notdodgeballN 1 Reply Last reply Reply Quote 0
          • notdodgeballN
            notdodgeball @Rowlfi_the_dog
            last edited by notdodgeball

            @Rowlfi_the_dog
            You can use the the “Paste to (Replace) Bookmarked Lines” menu option.

            Preferably you bookmark empty lines given that it will, like it said it would, replace whatever is on the line.

            You can also copy you snippet of code with a line break at the top, this way you can keep your empty line.

            1 Reply Last reply Reply Quote 2
            • Rowlfi_the_dogR
              Rowlfi_the_dog
              last edited by

              Hello,

              thank you for both answers !!

              But in the meantime I could solve my little problem myself …

              In case someone is interested, I will give a little description of how I did it:

              1.) Identify the location by a unique character (or series of those)
              2.) replace tab: “unique character as above” \n \n xyz
              3.) highlight the “xyz” with a bookmark
              4.) replace the bookmarked “xyz” with the clipboard

              Regards,
              Rowlfi

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors