Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Subword SelectionNew to Visual Studio Code? Get it now.
Subword Selection

Subword Selection

allenshuber

|
495 installs
| (1) | Free
Selects the subword section at the cursor location within the current word
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

subword-select README

Features

The subword-select extension selects the subword the cursor is currently located in.

There are extensions for both Visual Studio and Visual Studio Code that deal with subwords, such as moving between subwords and selecting them, but I've found nothing that allows selecting the subword the cursor is currently located in.

For example, the cursor is located in the variable name cur|rentItem and I want to change current to selected. To the best of my knowledge there is no way to do so, short of clicking and dragging, which is tedious. That's why I wrote this extension.

The extension scans for a large variety of special characters. The test cases are shown below.

// VS Code subword-test test cases

simpleWordSelection
simple-word-selection
simple_Word_Selection
Simple_Word_Selection
nameEndingInNumber55
nameWithInternal000Number
;leadingAndTrailingSemicolon;
;leading-and-trailing-semicolon;
:leadingAndTrailingColon:
:leading_and_trailing_colon:
.leadingAndTrailingPeriod.
.LeadingAndTrailingPeriod.
,leadingAndTrailingComma,
(leadingAndTrailingCloseParens)
[leadingAndTrailingSquareBracket]
{leadingAndTrailingCurlyBraces}
<leadingAndTrailingAngleBrackets>   
#leadingAndTrailingPound#
$LeadingAndTrailingDollarSign$      
?LeadingAndTrailingQuestionMark?    
~LeadingTilde
!leading-and-trailing-exclamation!  
@leading_and_trailing_ampersand@    
+leadingAndTrailingPlus+            
-leadingAndTrailingMinus-           (FAILS)(CONFUSED WITH SEPARATOR? SCAN LEFT FINDS "-" FIRST)
function aFunction(x, y)
x leadingAndTrailingSpace x
x   leadingAndTrailingTab   x
++increment++                       
--decrement--
ten=eight+two                       
WordWhichAre SeparatedByASpace
WordWhichAre    SeparatedByATab
"Surrounded By Double Quotes"       
'Surrounded By Single Quotes'       
Left&&Right                         

Requirements

None. This extension was designed for use with HTML, CSS, and JavaScript but might work with other markup or languages.

Extension Settings

This extension adds the subword-select command. I've mapped this command to Ctrl+Alt Space for a combination that's easy to get to: all the keys are on the bottom row and on the left side. An even better solution, although I'm not sure if it's technically possible, is to activate this command on the mouse click with a button held down, like Alt or Ctrl. It's something I'm researching. (Appears not: issue #3130, requesting it more than two years ago, is still open.)

Known Issues

None.

However, it should be noted that the coding approach dictates the results in certain cases. For example, activating the command with the cursor in the first subword in

-le|adingAndTrailingMinus-

selects the entire variable, except for the dashes. This is because the code scans to the left of the selection point for a special character and finds -, and then scans to the right for a matching character. Had the code scanned to the right it would have detected the A in And and seen leading as the selected subword.

Possible Future Enhancements

  • Do the initial search both ways to find the closest marker symbol?

Release Notes

0.0.1 (April 10, 2018)

Initial release of subword-select.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft