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

Allow using some characters as "wrapper" and "anchor" #20

Open
sangdth opened this issue Jun 6, 2023 · 2 comments
Open

Allow using some characters as "wrapper" and "anchor" #20

sangdth opened this issue Jun 6, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@sangdth
Copy link

sangdth commented Jun 6, 2023

Thanks for the great plugin! I would like to ask for something extra. It would be great if move.nvim can detect some popular wrapper and anchor characters and use it to swap horizontally everything between.

Please see examples below, | is the cursor:

Example of config:

require("move.nvim").setup({
    custom_anchors: { "{,}", "<,>" },
})

Example in usages:

In TypeScript, sometimes I want to swap the imports:

// before
import { |Something, type Other, Else } from 'somewhere';

// move.nvim can detect my cursor is inside the wrapper `{ ... }` with `,` anchor,
// so if I use MoveWord(1), it will become:
import { type Other, |Something, Else } from 'somewhere';

This is also useful in some cases like:

// before
forwardRef<SomeProps, typeof Other>(...)

// move.nvim can detect my cursor is inside `< ... >` wrapper with `,` anchor
// so if I use MoveWord(), it will become:
forwardRef<typeof Other, SomeProps>(...)
@sangdth sangdth changed the title Allow using some characters as "anchor" Allow using some characters as "wrapper" and "anchor" Jun 6, 2023
@fedepujol fedepujol self-assigned this Jun 12, 2023
@fedepujol
Copy link
Owner

Hey! Sorry for taking a long time to answer. MoveWord almost achieved that behaviour:

// before
import { |Something, Other, Else } from 'somewhere';

// doing MoveWord
import { Other, Something, Else } from 'somewhere';

But it doesn't work nice on the edges or in complex cases like the one you specified:

// before
import { |Something, type Other, Else } from 'somewhere';

// after MoveWord
import { type |Something, Other, Else } from 'somewhere';
// before
import { Something, type Other, Else| } from 'somewhere';

// after MoveWord
import { Something,  type Else| Other, } from 'somewhere';

I like the example config you proposed and we could extend it:

require('move').setup({
    word = {
        -- Creates the MoveWord command
        enable = true,
        -- We could change how MoveWord operates.
        -- delimited -> inside predefined wrappers with anchors
        delimited = {
            enable = true, -- by default this will be false
            -- Required only when `enable = true`. And it could be extendable.
            -- not sure about the naming `formulas`.
            formulas = { "<,>", "{,}" }
        },
    },
})

@fedepujol fedepujol added the enhancement New feature or request label Jun 15, 2023
@sangdth
Copy link
Author

sangdth commented Jun 15, 2023

Hi @fedepujol, thanks for your response, I understand that everybody has busy stuffs to handle, so no problem at all.

I agree with your suggestion. I'm also not sure about the naming but it still look good to me. Naming is hard, nobody can blame you :D

Really appreciate your time and effort 🙏🏻

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

No branches or pull requests

2 participants