Insert multiple lines of code before or after a specific place in code
-
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
-
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 haveBookmarkAndPaste
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.
-
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 -
@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.
-
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 clipboardRegards,
Rowlfi