Vim: FEATURE REQUEST: Add operator support for VSCodes new subword navigation

Created on 5 Jul 2018  路  13Comments  路  Source: VSCodeVim/Vim

The latest VSCode release added sub word navigation https://code.visualstudio.com/updates/v1_25

It would be really nice to be able to use these with vim operations like delete and change.

I have attempted to get this working through keybindings and user settings but cannot see any way to get this working currently.

Most helpful comment

_EDIT: updated with feedback from @AndrewJRichardson and @taybin, as well as my own usage_
Adding this to keybindings.json worked for me. (!inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible" can be removed if you want that, editorTextFocus && vim.active are the only important parts

    {
        "key": "q",
        "command": "cursorWordPartRight",
        "when": "editorTextFocus && vim.active && !inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible && vim.mode != 'Insert' &&  vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress'"
    },
    {
        "key": "shift+q",
        "command": "cursorWordPartLeft",
        "when": "editorTextFocus && vim.active && !inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible && vim.mode != 'Insert' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress'"
    },

All 13 comments

I don't believe vim normally has this functionality without camelcasemotion. I don't know if this extension generally implements other vim extensions, but natively, you can use /\u to bounce around camelcase with n and N, if you have ignore case on then use /[A-Z] instead.

You are right, Vim does not normally have this functionality without some awkward mappings to make it work with operators ( http://vim.wikia.com/wiki/Moving_through_camel_case_words , I am not sure this would work in this extension) or a script, though I would personally argue against limiting the usefulness of the extension just because Vim does not support it by default.

I don't know how difficult it would be to implement this. I am going off the assumption that the extension could piggyback on the navigation provided by VS Code, but there is a good chance I am completely wrong as I have not looked at the source code. Currently the navigation works, so I can use subword navigation to move around camelcase words but It cannot be used with operators such as d or c, unless I have missed a rebinding trick somewhere.

I came looking to ask for support in a camel case plugin, but this will do as well

_EDIT: updated with feedback from @AndrewJRichardson and @taybin, as well as my own usage_
Adding this to keybindings.json worked for me. (!inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible" can be removed if you want that, editorTextFocus && vim.active are the only important parts

    {
        "key": "q",
        "command": "cursorWordPartRight",
        "when": "editorTextFocus && vim.active && !inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible && vim.mode != 'Insert' &&  vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress'"
    },
    {
        "key": "shift+q",
        "command": "cursorWordPartLeft",
        "when": "editorTextFocus && vim.active && !inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible && vim.mode != 'Insert' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress'"
    },

@Cohedrin Nice tip for using sub-word navigation in vim (I'm using this now, thanks!), but not what the issue is about. The goal is to be able to do "d+q" for example (if following your key bindings) to delete a sub-word.

ah you're right, misread the issue. Don't have a solution for that, but glad it helped in any case.

actually, @Cohedrin those settings hijack the q key even in insert mode (can't type q whatsoever). do you know what when conditions can be added to avoid that?

Just add && vim.mode != 'Insert', should fix it.

This worked unexpectedly well for me, but I still hope do be able to integrate it better into the vim commands.

The keybindings trigger after typing / to enter search mode. So that I can't search for anything with a capital B or W (I have mine bound to shift+b and shift+w). Is there another variable I can check against to disable that in the keybinding? And is there a list of those variables somewhere?

Answered my own question:
"when": "editorTextFocus && vim.active && vim.mode != 'Insert' && vim.mode != 'SearchInProgressMode' && !inDebugRepl && !suggestWidgetMultipleSuggestions && !suggestWidgetVisible"

You want to make sure the mode isn't SearchInProgressMode as well. And the complete list of modes can be found in src/modes/modes.ts, although where the other variables come from, I'm not sure.

@taybin Sorry for the misleading post. Forgot to update after running into a few more issues with it. I've updated my original post now.

It's mostly the same the update you posted, but has the addition of the CommandlineInProgress flag, which allows your key bindings to be used when you have the vscode-vim command mode open.

The CamelCaseMotion plugin is useful but doesn't cover every use case. For example in languages such as css/scss where identifiers commonly contain dashes it can be helpful to modify vim.iskeyword to not include dashes but then there is no text object representing the subwords of those identifiers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndersenJ picture AndersenJ  路  3Comments

waltiam picture waltiam  路  3Comments

typeoneerror picture typeoneerror  路  3Comments

spinningarrow picture spinningarrow  路  3Comments

triztian picture triztian  路  3Comments