Keyboard shortcut for next/previous incremental search result?
OK, I see. I’ve now:
(1) Installed the Python Script plugin,
(2) Copied the Python scripts in the /plugins/PhytonScript/scripts folder
(3) Added the scripts in Plugins --> Phyton Script --> Configuration to the menu items
(4) Assigned shortcuts in Settings --> Shortcut Mapper --> Plugin Commands
It works – but only partly. This is what happens:
- When I open a file, open the incremental search window, search (ordinarily) for a text en then use the shortcuts for “FindNext” and “FindPrev”, nothing happens.
- If I invoke the scripts via Plugins --> Python Scripts (rather than via shortcuts), one of them (“FindPrev”) does work, the other (“FindNext”) doesn’t.
- If I use the shortcuts after the first call (via Plugins --> Python Scripts), “FindPrev” continues to work, but “FindNext” doesn’t.
This has nothing to do with the specific shortcuts I use. I have changed both shortcuts for testing, and the result was the same.
Is there anyone who has tried this as well? Is this an idiosyncrasy of my configuration or a general problem with Scott’s script?
This is a subtlety I hadn’t paid attention to before. Now that I think about it, the following seems the “minimum keystrokes” solution to me:
- You are in the document window in which you want to perform the search.
- You type (Ctrl+Alt+I) for opening the Incremental Search window (which you need anyway to type the text you are searching for).
- The first hit does not satisfy you, so you want the next one. This is while you are still in Incremental Search window, indeed.
Do you happen to have time for modification of the script along this line? I have no experience with Python whatever, nor with coding this type of scripts anyway, so I’m afraid that modifying it myself is not an option.
Is there anyone who has tried this as well?
I just tried the following series of steps:
- grab N++ 7.5.1 portable install; unzip it
- add Plugin Manager (ugh! and double-ugh!) by manual copying from my normal N++ install that I use normally
- run virgin 7.5.1 (with Plugin Mgr addition)
- install PS 1.0.8 via Plugin Mgr
- change PS config to be AT STARTUP instead of LAZY
- add the 2 scripts by copying text out of the code window from above in this thread, naming the files the same as indicated above
- in PS Configuration, add the 2 scripts so that they can be found by Shortcut Mapper
- in Shortcut Mapper, bind the “next” script to Ctrl+Shift+. (period)
- in Shortcut Mapper, bind the “prev” script to Ctrl+Shift+, (comma)
- invoke Incremental Search by pressing Ctrl+Alt+i
- put some text in the Find: box and press Enter
- press Esc (input focus is now back in doc I’m editing)
- press Ctrl+Shift+, and verify selection changes to previous occurrence of my Find: text – IT DID!
- press Ctrl+Shift+. and verify selection changes to next occurrence of my Find: text – IT DID!
Scott Sumner last edited by Scott Sumner
The first hit does not satisfy you, so you want the next one. This is while you are still in Incremental Search window
In this situation, just hit the Enter key. It will move the selection the the next match in the editor tab without leaving the Incremental Search pane.
Press Esc (which closes the Incremental Search pane) and returns input focus to the document tab you were on when you invoked the Incremental Search, leaving you ready to press:
- Ctrl+Shift+. (my shortcut, YSMV) to move the selection to the next match
- Ctrl+Shift+, (my shortcut, YSMV) to move the selection to the previous match
[YSMV = Your Shortcut May Vary]
Note: You can’t run a PS from an assigned shortcut when the Incr Seach pane has input focus.
Strangely enough, “FindPrev” works perfect in this way, whereas “FindNext” doesn’t.
I’ve adjusted the following line in the script of “FindNext”:
caption_of_button_to_press = '>' if 'FindNext' in currently_running_pythonscript else '<'
caption_of_button_to_press = '>'
(Actually you don’t need any experience with Python to do this). Now it works.
This suggests that I had somehow misspelled the file name, but as far as I can see, I hadn’t. Anyway, with this (admittedly ugly) fix it does work for me. Thanks a lot. Even after this cumbersome start, the investment will pay off in the long run.
Scott Sumner last edited by Scott Sumner
Yea…that was just my little technique to not have 2 files that differed only by one little thing–even having 2 identical files is not the best idea… It would be nice if you could pass arguments to pythonscripts or somehow know which keycombo invoked them, but this is not currently possible. [Actually both things are possible but not easy so I’ll just leave it there.] :-)
guy038 last edited by guy038
I simply asked myself the question :
How to have the editor window and the incremental search window present, at the same time and switch from one to the other, with a keyboard shortcut ? I found out a weird way to do it but, at least, it seems to work !
I supposed that you previously got the incremental search windows, hitting the
Alt + Ctrl + Ishorctut, once :
To move from the incremental search window to the main editor window, just hit the Win Logo key,
a first hit on the Win logo key, to get the Start menu
a second hit, on the Win logo key, to close the Start menu
As a result, the focus should be on the current editor window, with the cursor at its present location :-))
- To move from the main editor window to the incremental search window, simply hit, again, the
Alt + Ctrl + Ishorctut
And so on…
This method works nice on my [ old ] Wind XP laptop ! Just verify that it’s the same, on newer Windows OS ?!
ONCE the focus is on the incremental search window :
Tabkey, to cycle through the six zones ( Find zone, < and > buttons, Highlight all and Match case options , button X )
Shift + Tabshortcut, to cycle, in reverse order
To set/unset the Highlight all or Match case options, you may, either :
From any location, hit the
Alt + Hor
Alt + Cshortcuts
From the exact location, just hit the Space key
When a direction is chosen (
>), just press the
Enterkey, to go on searching, in the same direction
And, of course, hitting the
Escapekey, close the incremental search window !
just hit the Win Logo key, twice
Works for me on Windows 7 Enterprise SP1 64-bit, running Notepad++ 32-bit!
The double hit of the Windows logo key also more efficiently (less keystrokes) solves the problem from this thread: https://notepad-plus-plus.org/community/topic/12467/keystroke-to-switch-focus-from-console-window-to-active-editor-tab, although I’ll only use this new way interactively (and will keep the existing SendKeys-based solution in my startup.py).
I like it! :-D
The double-Windows-key works because when Notepad++ becomes the active application (second Windows logo keypress), focus is moved back to the current document tab if it was not there when N++ ceased being the active app. This seems to always be the case…
So another easy(?) keyboard option is to hold Alt+Tab and at the same time tap Esc! :-D
guy038 last edited by guy038
Hi @scott-sumner and All,
I did some tests and it happens that the double hit on the Windows logo key allows to put the focus back on the main editor windows, again, if a window can be anchored to the main editor windows, at its right, left, top or bottom side
So, it concerns, from native N++, the Character Panel, Clipboard History, Search Results, Project, Folder as Workspace and the Function List windows, as well as most of plugin’s windows as, for instance, the Python or Lua console window !
However, just note that if any of these “dockable” panels is not docked and is, simply, floating like a separate windows, the double hit on the Windows logo key does not allow, anymore, to have the focus back, on the main editor windows !
Strangely, it does not work too, with the Document Map panel, which, however, can be anchored !