Is there a way to enable camel humping through method names in VS Code?
Asked Answered
D

5

45

As this question is for the "big" Visual Studio and Resharper, I'd like to see that feature in VS Code too.

Scrolling through the shortcut list for VS Code, I couldn't find it but I'm hoping that it's still there but called something less intuitive than camel, hump or such.

Delicatessen answered 14/11, 2016 at 16:37 Comment(2)
is this question about moving the caret left and right? Or is it about selection expansion and contraction?Besmear
@Besmear It's actually both. The concept of camel-humping means that there's a way to schootch over to the next capital letter (as opposed to the next word). Whether I have SHIFT pressed (or whatever is the "selection" key on ones system) or not shouldn't matter. Unless you're referring to the expansion/contraction of a selection in both directions (to the next scope, however we may define it), then no, that's not what the OP intended.Delicatessen
S
5

I found this extensions to work https://marketplace.visualstudio.com/items?itemName=ow.vscode-subword-navigation

Funny thing is that you need to configure each combination separately:

{
    "key": "alt+left",
    "command": "subwordNavigation.cursorSubwordLeft",
    "when": "editorTextFocus"
},
{
    "key": "alt+right",
    "command": "subwordNavigation.cursorSubwordRight",
    "when": "editorTextFocus"
},
{
    "key": "alt+shift+left",
    "command": "subwordNavigation.cursorSubwordLeftSelect",
    "when": "editorTextFocus"
},
{
    "key": "alt+shift+right",
    "command": "subwordNavigation.cursorSubwordRightSelect",
    "when": "editorTextFocus"
},
{
    "key": "alt+backspace",
    "command": "subwordNavigation.deleteSubwordLeft",
    "when": "editorTextFocus"
},
{
    "key": "alt+delete",
    "command": "subwordNavigation.deleteSubwordRight",
    "when": "editorTextFocus"
}
Serendipity answered 8/8, 2017 at 6:1 Comment(2)
@Swaps you need to apply it to keybindings.json. The easiest way to access is just to type shortcuts in the command search window.Serendipity
This feature is now integrated in the application: no Plugin needed see: https://mcmap.net/q/367239/-is-there-a-way-to-enable-camel-humping-through-method-names-in-vs-codeAgeold
W
87

As of version 1.25 these commands are built in:

enter image description here

Wylma answered 13/7, 2018 at 16:14 Comment(4)
This is solid, you can rebind them all without the alt key and it's just perfectIsochronal
This should be changed to the accepted solution! Thanks.Foxtail
Using the Ctrl - Alt - Delete keybinding on Windows won't work.Capello
Please don't embed URL based images, as often these are blocked by eg. VPN firewalls etc.Ego
S
5

I found this extensions to work https://marketplace.visualstudio.com/items?itemName=ow.vscode-subword-navigation

Funny thing is that you need to configure each combination separately:

{
    "key": "alt+left",
    "command": "subwordNavigation.cursorSubwordLeft",
    "when": "editorTextFocus"
},
{
    "key": "alt+right",
    "command": "subwordNavigation.cursorSubwordRight",
    "when": "editorTextFocus"
},
{
    "key": "alt+shift+left",
    "command": "subwordNavigation.cursorSubwordLeftSelect",
    "when": "editorTextFocus"
},
{
    "key": "alt+shift+right",
    "command": "subwordNavigation.cursorSubwordRightSelect",
    "when": "editorTextFocus"
},
{
    "key": "alt+backspace",
    "command": "subwordNavigation.deleteSubwordLeft",
    "when": "editorTextFocus"
},
{
    "key": "alt+delete",
    "command": "subwordNavigation.deleteSubwordRight",
    "when": "editorTextFocus"
}
Serendipity answered 8/8, 2017 at 6:1 Comment(2)
@Swaps you need to apply it to keybindings.json. The easiest way to access is just to type shortcuts in the command search window.Serendipity
This feature is now integrated in the application: no Plugin needed see: https://mcmap.net/q/367239/-is-there-a-way-to-enable-camel-humping-through-method-names-in-vs-codeAgeold
C
5

If for some reasons your bindings are not set here is the JSON to obtain Cezn's shortcuts.

{
    "key": "ctrl+alt+right",
    "command": "cursorWordPartRight",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+shift+right",
    "command": "cursorWordPartRightSelection",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+left",
    "command": "cursorWordPartLeft",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+shift+left",
    "command": "cursorWordPartLeftSelection",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+backspace",
    "command": "deleteWordPartLeft",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+alt+delete",
    "command": "deleteWordPartRight",
    "when": "editorTextFocus && !editorReadonly"
}

Be careful with the ctrl+alt+delete one since it conflicts with another popular windows shortcut.

Other interesting bindings are:

{
    "key": "ctrl+n",
    "command": "explorer.newFile",
    "when": "explorerViewletFocus"
},
{
    "key": "ctrl+shift+n",
    "command": "explorer.newFolder",
    "when": "explorerViewletFocus"
}
Choroiditis answered 1/10, 2020 at 11:53 Comment(0)
T
1

There is an extension for this: Camel Case Navigation

enter image description here

Treacherous answered 1/12, 2021 at 13:7 Comment(0)
C
1

Adjusted this answer so it works with v1.91 (keep in mind ctrl+alt+delete might not work properly on windows)

{
    "key": "ctrl+alt+right",
    "command": "cursorWordPartRight",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+shift+right",
    "command": "cursorWordPartRightSelect",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+left",
    "command": "cursorWordPartLeft",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+shift+left",
    "command": "cursorWordPartLeftSelect",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+alt+backspace",
    "command": "deleteWordPartLeft",
    "when": "editorTextFocus && !editorReadonly"
},
{
    "key": "ctrl+alt+delete",
    "command": "deleteWordPartRight",
    "when": "editorTextFocus && !editorReadonly"
}
Coronet answered 19/7 at 19:34 Comment(5)
I can't see the difference. What was changed compared to the original?Delicatessen
Commands changed slightly and I removed the ctrl from them: cursorWordPartRightSelection -> cursorWordPartRightSelect; cursorWordPartLeftSelection -> cursorWordPartLeftSelectCoronet
Ah, I see. I'd suggest to re-add the CTRL key as it's the common (at least on Windows) way to denote a "word". It's originally used for a complete word but in camelCasedSyntax the concept of "word" refers to separation by capitalization, not only white space.Delicatessen
I guess that would be one way to look at it, from my POV alt+arrow is also fine, no need to have it more complex and the legacy subword navigation extension used this combination too IIRC. BUT I googled and found out that visual studio has by default built in subword navigation so I will change it to ctrl+alt as you suggested so its consistent with VS defaultsCoronet
Yes, please do. However, it's not VS Code standard. It's Windows standard (or rather MS convention). Confusing to Mac'ies and Ux'es as much as the roundy-rectangly thing is on their systems. :DDelicatessen

© 2022 - 2024 — McMap. All rights reserved.