Shortcut-key for selecting word (i.e. double-click)
-
I would like to assign a shortcut key to the same functionality that we can achieve (and tune via Settings/Delimiter/Word Character List) by double-clicking. I cannot find this “select word” function anywhere in the menu, so I don’t know how to map it myself.
-
Well, you can approximate it by recording a macro and assigning a keycombo to run that macro:
- Ctrl+LeftArrow
- Shift+Ctrl+RightArrow
This will work as long as your caret is not at the very beginning of the word you wish to select. If your caret is there, simply do Shift+Ctrl+RightArrow to select the word.
-
@Alan-Kilborn
Thanks. Since the functionality already exists with doubleclick I would prefer if I could just assign a hotkey to the same function. I guess that somewhere it exists an ID that can be assigned to a hotkey -
@Greven-of-Norway said in Shortcut-key for selecting word (i.e. double-click):
Since the functionality already exists with doubleclick I would prefer if I could just assign a hotkey to the same function
Now if that were true, don’t you think I would’ve told you how to do that?
Of course, perhaps someone else knows more than I about it.I purposely avoided proposing a script-based solution for this, because it is rather “heavy”, but it is possible and easy to do a script for this.
-
@Greven-of-Norway said in Shortcut-key for selecting word (i.e. double-click):
I guess that somewhere it exists an ID that can be assigned to a hotkey
Not a single ID, that I can find. (It’s weird, because Scintilla has commands for nearly everything, but they specifically say “Double clicking selects the word at that point” in the section on WORD-based commands, but don’t map that description to a particular command, and the commands they do list don’t implement exactly that functionality. Poor choice on their part, IMO.)
As a close approximation, add the following to the
<Macros>
section of the%AppData%\Notepad++\shortcuts.xml
🛈 (or equivalent for non-normal installations), save, then restart Notepad++.<Macro name="SimulateDoubleClickWord" Ctrl="yes" Alt="yes" Shift="yes" Key="87"> <Action type="0" message="2308" wParam="0" lParam="0" sParam="" /> <Action type="0" message="2442" wParam="0" lParam="0" sParam="" /> </Macro>
From then on,
Ctrl+Alt+Shift+W
will run SimulateDoubleClickWord macro (shortcut can be changed in the Macro > Modify Shortcut), which will do the commands for SCI_WORDLEFT followed by SCI_WORDRIGHTENDEXTEND (aka,Ctrl+LeftArrow
thenCtrl+Shift+RightArrow
). With that macro, as long as your caret (the typing “cursor”, usually a vertical bar) is inside the word, it will select the whole word. (The only practical difference I could see between that and double-click is that double-click would allow you to double click on the left side of the first letter of a word, like on the left side of thea
inapple
, whereas this macro requires that the caret/cursor be between thea
and thep
as the farthest left it can be. If your caret is before the first character of the word, you can either move it right one character then run the macro, or you could justCtrl+Shift+RightArrow
from there.).It’s not perfect or exactly what you want, but it’s the best that can be done from native Notepad++.
If you have the PythonScript plugin installed, it can go one step better than the macro, and can test if it’s at the start of the word first, then decide whether to do the SCI_WORDLEFT first or just do the SCI_WORDRIGHTENDEXTEND, making it functionally identical to doubleclick, as far as I can tell.
from Npp import editor p = editor.getCurrentPos() if editor.wordStartPosition(p,True) < p: editor.wordLeft() editor.wordRightExtend()
FAQ: How to install and run a script in the PythonScript plugin
-
BTW, this has all been beat to death before; see https://community.notepad-plus-plus.org/topic/17355/select-word
-
If we’re going script, here’s the one I’ve been using for a LONG time; I have it remapped to Ctrl+w:
p = editor.getCurrentPos() s = editor.wordStartPosition(p, True) e = editor.wordEndPosition(p, True) if s != e: editor.setSelection(e, s) # now we have the word selected, but some N++ commands that work on selections (e.g. convert to UPPERCASE) are dimmed out and won't work! # here's a workaround for that: editor.swapMainAnchorCaret() # put caret at start of word editor.swapMainAnchorCaret() # put caret back to end of word
-
@PeterJones Thank you very much! I have never looked into the PythonScript plugin, but I will definitely do that!
-
@Alan-Kilborn Nice! Thank you very much!