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

wrapper functions which can be used to define count prefixed, dot repeatable keymaps #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tummetott
Copy link

@tummetott tummetott commented Feb 9, 2023

The added wrapper functions can be used in keymaps like following:

vim.keymap.set(
    'n',
    '[s',
    function ()
        vim.go.operatorfunc = "v:lua.require'iswap'.iswap_node_with_left"
        return 'g@l'
    end,
    { desc = 'Swap with [count] left node', expr = true }
)

vim.keymap.set(
    'n',
    ']s',
    function ()
        vim.go.operatorfunc = "v:lua.require'iswap'.iswap_node_with_right"
        return 'g@l'
    end,
    { desc = 'Swap with [count] right node', expr = true }
)

The resulting keymaps are dot repeatable and can be prefixed with [count].
Examples: 2[s, ]s

closes #68

@mizlan
Copy link
Owner

mizlan commented Feb 10, 2023

Is there a way to make setting up a dot-repeatable keymap easier than this? It seems like there still is a bit of boilerplate for the user when configuring this way.

@tummetott
Copy link
Author

I'm only aware of two methods getting dot repetition. One is using operatorfunc as I did, the other is using a third party plugin like vim-repeat. I could never understand the code of vim-repeat since I'm not familiar with vimscript. I've noticed that you added vim-repeat support in your plugin already. However I don't like having an extra plugin for this.

See this link

The implemented version with vim-repeat is a little broken too: When I swap a node with :ISwapWithLeft and then press ., then I get promped to pick a node to swap with. I would expect that the :ISwapWithLeft command is re-executed, but in reality the :ISwapWith command is executed.

@mizlan
Copy link
Owner

mizlan commented Feb 10, 2023

understood, thanks! Can I put the operatorfunc bit into my plugin as opposed to the user putting it into their configuration.

@tummetott
Copy link
Author

Yes that would be possible. I can make a PR for this next week.

@mizlan
Copy link
Owner

mizlan commented Feb 11, 2023

thanks! i would appreciate that a lot. i'm not super familiar with operatorfunc

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.

Dot repeatable
2 participants