Shortcut for bookmark selected text?
Is there any way to mark a block, and pressing a shortcut, bookmark all the coincidences in the file? I tried to make a macro for the task without success.
(Currently I have to press control-F, select the mark tab, check the bookmark line and press “mark all”).
Is a task I use 10 times a day, a shorcut for that task will be welcome.
may I ask what your final goal is. Is it just to have a visible indication about
the same text or do you want to use bookmark function like cutting
the bookmarked text or non-bookmarked text etc. ?
Thanks for your time. Is a mix :
50% times: f2 is a useful way to go to the next patch line without loose the attributes like color mark,
20% times: replace text (with a visible mark to replace / test / undo replace only in some)
10% times: copy all bookmarkes lines to a new file
10% times: cut all bookmarks
10% times: inverse selection
Hello, Grenville Tryon,
I’ve been able to build a macro, which can be launched with a shortcut, to mark all occurrences of a specific text. But, unfortunately, as we cannot enter parameters, in N++'s macros, this text to search is written, namely :-((
For instance, if you insert, in the macro section, of your active shortcuts.xml file, the text below, it would bookmark all lines, containing, at least, one occurrence, of the word Test, with that exact case, in normal search mode and downwards direction
<Macro name="Mark Occurrences" Ctrl="yes" Alt="yes" Shift="no" Key="77"> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="Test" /> <Action type="3" message="1625" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1702" wParam="0" lParam="530" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1615" sParam="" /> </Macro>
Note that you must :
Close any N++ instance, first
Edit the Shortcuts.xml file, with an OTHER editor than Notepad++ ( Important ! )
Insert the block of text and save it
Finally, re-open N++
Later, you should change, in Shortcuts.xml, the present word Test by the other word to search for :-(( Not acceptable, of course !
But, certainly, your goal could be achieved with a Python or Lua script !
@guy038 , I tried your shortcut test as indicated and works as desired (as you marked, only for the “Test” word). Still looking, but you gave a couple of clues. Thanks!
the problem with macros and selected text is that it records the text as well,
which, I guess, isn’t desirable in your case.
What I could offer would be a python script, which basically emulates
npps bookmark functionality. This has the advantage that you can use npps
builtin functions like cut bookmarked lines, clear bookmark etc.
If you haven’t installed python script plugin already than I would suggest
to download the msi from here instead using plugin manager.
Once installed, run Plugins->PythonScript->New Script, give it a meaningful name
and put the following into it.
SCE_UNIVERSAL_FOUND_STYLE = 31 MARK_BOOKMARK = 24 def clear_previous_marks(): editor.setIndicatorCurrent(SCE_UNIVERSAL_FOUND_STYLE) editor.indicatorClearRange(0,editor.getTextLength()) editor.markerDeleteAll(MARK_BOOKMARK) def match_found(m): targetStart = m.span(0) foundTextLen = m.span(0) - m.span(0) editor.setIndicatorCurrent(SCE_UNIVERSAL_FOUND_STYLE) editor.indicatorFillRange(targetStart, foundTextLen) lineNumber = editor.lineFromPosition(targetStart) editor.markerAdd(lineNumber, MARK_BOOKMARK) clear_previous_marks() pattern = editor.getSelText() if pattern != '': editor.research(pattern, match_found)
Now you either can assign a shortcut or put it into the context menu (right click menu).
If you need help solving this - let us know.
Work exactly as needed. Thank you very much, you made my day!
just noticed that I was using
but maybe you wanna use
instead, otherwise the string is treated as a regular expression.