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 request: custom text objects/motions #1096

Open
timkendrick opened this issue Nov 29, 2016 · 13 comments
Open

Feature request: custom text objects/motions #1096

timkendrick opened this issue Nov 29, 2016 · 13 comments

Comments

@timkendrick
Copy link

I'm an Atom vim-mode-plus user who's been keeping an eye on VSCode for a while: one of the main things that's holding me back from switching is the inability to define various text objects and motions that I've grown accustomed to.

Some examples of custom text objects in other 'vimplementations':

Is there any chance that this kind of extensibility will be available for text objects and motions within VSCode Vim some day?

@johnfn
Copy link
Member

johnfn commented Nov 29, 2016

Our current policy on extensions is that while we probably won't implement them ourselves, we're completely open to other users implementing them. We're also completely fine with merging them into VSCodeVim core (generally speaking under a flag).

@timkendrick
Copy link
Author

Sounds great, thanks for the fast response!

@johnfn
Copy link
Member

johnfn commented Dec 1, 2016

Gonna keep this open as it's a valid feature request.

@tylerthehaas
Copy link

I also would very much like to see this. Any work going on with this?

@sunnyrjuneja
Copy link

Hey everyone,

Subword support has been added to VS Code in 1.25 (microsoft/vscode#48023). Is it possible to enable subword for motion hot keys?

@muhajirdev
Copy link

Any progress on this?

@skywind3000
Copy link

skywind3000 commented Feb 6, 2020

Still no progress ??

@sql-koala
Copy link
Contributor

sql-koala commented Feb 12, 2021

subword movement is supported:
https://github.com/VSCodeVim/Vim/blob/master/README.md#camelcasemotion
indent is also supported, keys: ii, ai

@danielo515
Copy link

I'm particularly interested on the function text object.
Is it possible to take advantage of any LSP to not have to parse it? I mean, can this extension communicate with LSP?

@nwaywood
Copy link

nwaywood commented May 3, 2021

A text object not mentioned here yet that I use a lot is https://github.com/kana/vim-textobj-line

@nudopnu
Copy link

nudopnu commented Jan 5, 2024

I would also love to see xmlattr https://github.com/whatyouhide/vim-textobj-xmlattr

@haukurb
Copy link

haukurb commented Mar 18, 2024

A text object not mentioned here yet that I use a lot is https://github.com/kana/vim-textobj-line

For any who also ended up here when looking for line text objects, most of it can be emulated with the "before-after" functionality:

{
    //   ...
    "vim.normalModeKeyBindingsNonRecursive": [
        // hacks for line text object
        {
            // delete inner line
            "before": ["d", "i", "l"],
            "after": ["^", "d", "g", "_"],
        },
        {
            // change inner line
            "before": ["c", "i", "l"],
            "after": ["^", "c", "g", "_"],
        },
        {
            // go replace inner line
            "before": ["g", "r", "i", "l"],
            "after": ["^", "g", "r", "g", "_"],
        },
        {
            // go UPPER inner line
            "before": ["g", "U", "i", "l"],
            "after": ["^", "g", "U", "g", "_"],
        },
        {
            // go upper inner line
            "before": ["g", "u", "i", "l"],
            "after": ["^", "g", "u", "g", "_"],
        },
    ],
    // ...
    "vim.visualModeKeyBindingsNonRecursive": [
        // hacks for line text object,
        {
            // select inner line
            "before": ["i", "l"],
            "after": ["^", "v", "v", "$", "o"],
        },
        {
            // select around line
            "before": ["a", "l"],
            "after": ["0", "v", "v", "$"],
        }
    ],
    // ...
}

This catches the most frequent usages and is easily extended to "around-line" objects (for preceding space + trailing space).

The surround command ys uses (I think) operatorPendingMode so it needs a different approach.

@max-sixty
Copy link
Contributor

In the spirit of sharing hacky regexes, here's an attempt at a selecting comment block. g; selects a contiguous comment block while g: selects comment blocks separated by newlines.

g; currently has an issue in that the selection moves to the bottom of the buffer; thoughts on fixing it are very welcome!

    // Selects single-line comments blocks, starting with `#` or `/`
    // <g;> doesn't expand over blank lines, <g:> does
    // We have to write out the whole regex in single characters, which makes it
    // illegible, unfortunately. But the regex is:
    // - `^(\s*[^\s#/])` for `<g:>`
    // - `^(\s*[^\s#/]|$)` for `<g;>`
    {
      "after": [
        "?",
        "^",
        "(",
        "\\",
        "s",
        "*",
        "[",
        "^",
        "\\",
        "s",
        "#",
        "/",
        "]",
        ")",
        "<Enter>",
        "j",
        "V",
        "/",
        "^",
        "(",
        "\\",
        "s",
        "*",
        "[",
        "^",
        "\\",
        "s",
        "#",
        "/",
        "]",
        ")",
        "<Enter>",
        "k"
      ],
      "before": ["g", ":"]
    },
    {
      "after": [
        "?",
        "^",
        "(",
        "\\",
        "s",
        "*",
        "[",
        "^",
        "\\",
        "s",
        "#",
        "/",
        "]",
        // By hitting this key without hitting the next one yet, the top of the
        // file is highlighted, which makes moves the selection to the bottom of
        // the screen. TODO: find a way of entering the whole regex without a
        // redraw. If we paste it, then it works, so some way is possible.
        "|",
        "$",
        ")",
        "<Enter>",
        "j",
        "V",
        "/",
        "^",
        "(",
        "\\",
        "s",
        "*",
        "[",
        "^",
        "\\",
        "s",
        "#",
        "/",
        "]",
        "|",
        "$",
        ")",
        "<Enter>",
        "k"
      ],
      "before": ["g", ";"]
    },

I'd very much like a a feature to define a mapping between a chord and a text selection — so rather than having to define dil, dal, cil, cal, vil, val etc — we could just define il & al mean, and for the extension to handle it in each action.

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

No branches or pull requests