Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix black hole operator mappings #3081

Merged

Conversation

shawnaxsom
Copy link
Contributor

@shawnaxsom shawnaxsom commented Sep 29, 2018

What this PR does / why we need it:

It is somewhat common in Vim to remap keys to copy to the black hole register, when the user doesn't want to modify the default register. In our current remapping system, this wasn't supported with operators when the operator was a repeated key press (e.g. dd with "_d mapped).

Vanilla Vim seems to disregard key mappings if an operator is in progress. dd with "_d mapped should result in "_dd, not "_d"_d. So this change seems in line with vanilla as far as that goes.

Therefore, with this PR, the following vscode setting should allow e.g. dd and dw to become "_dd and "_dw, thereby yanking to the black hole register and not overwriting the default register or the system clipboard.

{
     "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["d"],
            "after": [ "\"", "_", "d" ]
        }
    ]
}

Which issue(s) this PR fixes

fixes #2672

Special notes for your reviewer:

Note that there are still issues with mapping, such as if you want to map both d and dd. But those don't appear to be regressions. Vanilla Vim handles the following scenarios:

Mapping "w" does NOT affect the "w" in "dw"
Mapping "dd" should change "dd"
Mapping "d" and "dd", it uses "dd" remap if "dd" is pressed, otherwise it waits for a timeout to do "d" remap
Mapping just "d", it realizes there are no mappings that involve additional keystrokes, so it applies "d" remap immediately

It seems we would need to e.g. revamp how the remapper timeouts work in ModeHandler if we wanted to handle these. I could open a separate GitHub issue to tackle that.

Note that not all vanilla Vim test cases pass, but those seem to be
existing issues with how we handle remapping timeouts. Those can be
opened as a separate issue. Namely, not all of these pass:
Mapping "d" should change the first "d" in "dw"
Mapping "w" does NOT affect the "w" in "dw"
Mapping "dd" should change "dd"
Mapping "d" and "dd", it uses "dd" remap if "dd" is pressed, otherwise
it waits for a timeout to do "d" remap
Mapping just "d", it realizes there are no mappings that involve
additional keystrokes, so it applies "d" remap immediately
@escamoteur
Copy link

I just tried this, but and it works if I press dd. But then I press 4d it too is moved to the black hole.
So I still can't map dd

@berknam
Copy link
Contributor

berknam commented Oct 5, 2020

I just tried this, but and it works if I press dd. But then I press 4d it too is moved to the black hole.
So I still can't map dd

This is an old PR. If you're using version 1.17+ then the remapper has been overhauled. Explain what you want to do. If you're trying to do something that works in normal VIM but doesn't with VSCodeVim then open an issue.

If you're trying to make all deletes using key d delete to black hole register then you can use the mapping showed above:

"vim.normalModeKeyBindingsNonRecursive": [
    {
        "before": ["d"],
        "after": [ "\"", "_", "d"]
    }
]

This will make all deletes in normal mode using 'd' delete to black hole register, like dw, 4dw or dd. If you just want to change the dd for when deleting an entire line then you can do:

"vim.normalModeKeyBindingsNonRecursive": [
    {
        "before": ["d", "d"],
        "after": [ "\"", "_", "d", "d"]
    }
]

If instead you want to make the delete with 'd' go to black hole register except when deleting an entire line then you can do it like this:

"vim.normalModeKeyBindingsNonRecursive": [
    {
        "before": ["d"],
        "after": [ "\"", "_", "d"]
    },
    {
        "before": ["d", "d"],
        "after": [ "d", "d"]
    }
]

That last one is just to make sure that dd uses the normal d instead of the remapped d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remapping d to always delete to black-hole
4 participants