In just about all modern text-reading and text-writing applications, a double-left-click with the mouse on a word in the text causes that word to become selected. Double-clicking a word in this manner is handy for quickly selecting a word in order to copy-and-paste or cut-and-paste it elsewhere, or to just delete the word. (If you've never used double-click in this way before, go ahead and give it a try on one of the words in this post, right here in your web browser.)
I've recently noticed that not all applications handle double-click-selection of words that contain an underscore character (the character "_"; also called "underbar") in the same way. Such words are frequently used by software developers for naming such things as variables and database fields; examples are max_records and customer_id.
In some applications, double-clicking on any portion of a word containing an underscore results in the entire word being selected. This is the behavior I want, since it lets me easily cut or copy the entire identifier elsewhere. (For example, taking the example of the max_records identifier, if I double-click the word, it's far more common that what I'm trying to do is select and copy "max_records" for pasting elsewhere, rather than just "max" or just "records".) The text editor Notepad2 works this way (shown here after a double-click on the word "max"):
The problem is that in some applications, double-clicking a word containing an underscore results in just the clicked portion of the word becoming selected; the underscore gets treated as a word separator character (like a space character would be treated). Firefox 3 works this way (again, shown after a double-click on "max"):
Since typical (non-developer) users are seldom or never going to be working with documents with words that include underscore characters (and therefore aren't affected one way or another by what the behavior is), I think that the default behavior across all applications should be to select the entire word when a word including an underscore character is double-clicked. The underscore should not be treated as a word separator character for the purposes of an application's logic that selects a word on a double-click.
It still might make sense for underscore characters to be treated as word separator characters in some other cases. Such cases might include an application's spell check logic; another case might be the handling of navigating through a document a word at a time via the Ctrl+LeftArrow and Ctrl+RightArrow shortcut keys.
A few applications that get this behavior "right" (double-click selects an entire word with an underscore; not all other punctuation characters are specially handled this way):
- Visual Studio 2008
- Eclipse 3.3
- Notepad2 (2.1.19)
- Microsoft Excel (2003)
A few applications that don't get the double-click behavior "right" (double-click selects only the portion of the clicked word up to the underscore character):
- Firefox 3
- Internet Explorer 6
- Toad for Oracle (9.0.1.8)
- Microsoft Word (2003)
- Acrobat Reader 7
Developers of this latter set of applications: If you agree, please go forth and effect positive change! :-) Developers of new applications, please keep this issue in mind when coding up the mouse click UI behavior for your new app.
Update 4/4/2011: There is an existing, long-standing (March 2003) Mozilla (Firefox) Bugzilla ticket for this: Bug 196175 - underscore should be part of word, not punctuation. As discussed in that comments on that ticket, though, it isn't clear that special-case logic should be added for the underscore character, since behavior from application to application even on a single platform is inconsistent (as I noted above for Windows applications). I voted for the ticket, but I'm not going to hold my breath at this point for it to be addressed soon!
Good post! This is exactly what we want: underscore treated as a word character when selecting, but as a separator character for the purposes of spell-checking.
ReplyDeleteFor FF 3, you can change this in about:config
ReplyDeletehttp://kb.mozillazine.org/Layout.word_select.stop_at_punctuation
OMG - Perfect - I have been searching for this literally for years
Delete.... here is 12 year old ticket
https://bugzilla.mozilla.org/show_bug.cgi?id=196175
@george anderson - I hadn't been aware of that Firefox setting -- thanks for pointing it out!
ReplyDeleteHowever, the setting apparently only gets us part of the way there -- not only does it enable whole-word selection for words with underscores (like: user_name), it causes a double-click to select across *all* punctuation characters (like: user.name). My ideal behavior (as described in the original post) would be for a double-click select to select across underscore characters, but not other punctuation characters.
As a side comment, I'm frustrated with how different brands of mice implement double-click macros differently. Try this manually: double-click on the first word in a sentence, but do not release the second click, then drag your mouse over subsequent words. You'll notice that this puts the selection behavior into word-select mode, which is very handy in programming and for those of us who have disabled "select entire word" in our MS Word and Outlook settings (by default we select single characters, but double-click+drag selects entire words).
ReplyDeleteMost extra-buttoned mice come with a double-click macro that can be assigned to a button, but so far only Microsoft mice seem to get it right and allow the double-click+drag capability. Logitech and Razor mice get it wrong. With Logitech, the second click is released even if you don't release the mouse button, so you can't drag. With Razor, even weirder things happen -- the second click doesn't happen until releasing the button, and sometimes an extra click gets thrown in for good measure (triple-click).
I've adopted these erroneous behaviors as a pet peeve. Bad dog! Bad dog!
@Anonymous -- I never knew about the double-click-drag operation. Thanks for the pointer!
ReplyDeleteHave you ever contacted Logitech or Razor about this? Maybe their developers don't know about the problem?
Strongly agree!
ReplyDeleteTo me "this_set_of_characters" is one word.
I agree as well. TOAD has had this option since about version 7.x. The option is "Treat underscore as a word character".
ReplyDeleteNobody has filed this in bugzilla yet then?
ReplyDelete@Anon (5:16p): Not that I'm aware of, no, although I haven't searched. Feel free to do so and link the issue here, and I'll update the main post above!
ReplyDeleteOne comment about Eclipse... it gets the underscore thing half-right. Yes, if you double-click on a token with underscores, it highlights the entire token. But, if you navigate text with Ctrl-Left or Ctrl-Right (previous/next word), the cursor jumps along as if the underscore is a delimiter. For the life of me, I can't seem to find the setting in Eclipse that would force the "Next Word" or "Previous Word" commands, to which those keys are bound, to treat underscore as any other hard character. Annoying. One of the reasons why I haven't embraced Eclipse as my primary code editor (I've used EmEditor for years and love it).
ReplyDeleteI couldn't find that setting either. This is just awful. If anyone knows please let us know.
ReplyDeleteAnyone have any fixes for Word 2010 (or other versions)? I've seen some macros out there, but that solution seems a little cumbersome. It's very annoying to write documentation and to have to tediously copy each variable_name. Especially_since_Google_Chrome_does_this_right_and_allows_me_to_highlight_this_whole_sentence_with_a_double_click.
ReplyDeleteI agree, it would be great if MS Word could have this as a config option.
DeleteNo solutions?
ReplyDeleteThis bug can be really annoying when developing OpenGL apps... Chrome gets underscores right, but Chrome's support for MathML is nearly non-existent at the moment, and it is used frequently on http://www.opengl.org/sdk/docs/man/
ReplyDeleteI find Mozilla's lack of support for this nothing short of insane. There is so much code talk that happens on the web, how could they eat their own dog food and remain sane with this bug? And Microsoft Outlook is especially frustrating when talking about code. This is a no-brainer. Get it done.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI've wrote VBA marco for MS Word:
ReplyDeleteCreate a class named "underscoreDoubleClick":
-------------------------------------------------------------------------
Public WithEvents appWord As Application
Const characters As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private flagDoubleClick As Boolean
Private Sub appWord_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
flagDoubleClick = True
End Sub
Private Sub appWord_WindowSelectionChange(ByVal Sel As Selection)
If flagDoubleClick Then
If Selection.characters.First.Text = "_" And InStr(characters, Selection.Previous(Unit:=wdCharacter, Count:=1).Text) Then
Selection.Start = Selection.Previous(Unit:=wdWord, Count:=1).Start
End If
If Selection.characters.Last.Text = "_" And InStr(characters, Selection.Next(Unit:=wdCharacter, Count:=1).Text) Then
Selection.End = Selection.Next(Unit:=wdWord, Count:=1).End
End If
While Selection.Next(Unit:=wdCharacter, Count:=1).characters.First.Text = "_"
Selection.End = Selection.End + 1
If InStr(characters, Selection.Next(Unit:=wdCharacter, Count:=1).Text) Then
Selection.End = Selection.Next(Unit:=wdWord, Count:=1).End
End If
Wend
While Selection.Previous(Unit:=wdCharacter, Count:=1).characters.Last.Text = "_"
Selection.Start = Selection.Start - 1
If InStr(characters, Selection.Previous(Unit:=wdCharacter, Count:=1).Text) Then
Selection.Start = Selection.Previous(Unit:=wdWord, Count:=1).Start
End If
Wend
flagDoubleClick = False
End If
End Sub
-------------------------------------------------------------------------
Create a module:
-------------------------------------------------------------------------
Dim X As New underscoreDoubleClick
Sub Register_EventHandler()
Set X.appWord = Word.Application
End Sub
-------------------------------------------------------------------------
Then we should initialize event handler when weopen word document, add this to "ThisDocument":
-------------------------------------------------------------------------
Private Sub Document_Open()
Call Register_EventHandler
End Sub
-------------------------------------------------------------------------
Lets no be shy in keeping an 8 year old thread alive!
ReplyDeleteIn Office 2013 if you hold down CTRL when selecting it will select the whole word as you want it to (where underscores are considered part of the word)
Ah crap, ignore my post above on the CTRL key, it doesn't work. I was desperately trying to find a solution to this, and inadvertently tested this on a list of such underscored words, where only those words are in the list. CTRL select selects the whole line, but in such a list, this is just the word. I was so excited I found a solution, I posted in haste. Dang, back to the drawing board
ReplyDelete@Anon:
ReplyDeleteSorry to hear it didn't work!
A better-than-nothing workaround might be to double-click the first part of the word, then keep holding down the mouse on the 2nd click and drag to select the remainder of the word.
Double-click-drag selects entire words at a time, so that might at least save you from the annoying thing of trying to position the mouse in a drag-to-select with perfect precision such that the characters in your word, but no more, are selected!
I've created a small MS Word add-on to mend this (and some other) issue. If anyone's still interested please give it a try. Word of warning (pun not intended) it may be buggy at this stage :)
ReplyDeleteAnyways you can grab it at: https://battlepuli.com/selectron/
I wholeheartedly disagree and hate that more applications are moving to the proposed behavior because it makes one group's life marginally easier while making the other group's significantly harder.
ReplyDeleteNow to select actual individual words in snake_case I have to double-click, then switch to keyboard and meticulously tap Left-arrow while holding Shift (because of course Ctrl+Left-arrow will just deselect everything).
All you had to do to select multiple words was drag mouse a little after double-clicking (or tap Ctrl+Right-arrow once), and it would auto-select the next word.
One step forward, two steps back.
I am 100% with Derrick here. I found this post trying to find out how to STOP windows from selecting across any punctuation, underscores and periods being the most common. My personal issue is with accidentally deleting file extensions when I just want to rename the last word.
ReplyDelete