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

Repeat movements like ; and , #359

Merged
merged 8 commits into from
Jan 17, 2023

Conversation

kiyoon
Copy link
Collaborator

@kiyoon kiyoon commented Jan 13, 2023

Implements #340

Supports normal, visual and operator-pending modes, v:count1 count repeat, and optionally builtin f, F, t, T mappings if you want to use the same ; bindings.

local tstextobj_move = require "nvim-treesitter.textobjects.move"

-- Repeat movement with ; and ,
-- ensure ; goes forward and , goes backward
vim.keymap.set({ "n", "x", "o" }, ";", tstextobj_move.repeat_last_move_next)
vim.keymap.set({ "n", "x", "o" }, ",", tstextobj_move.repeat_last_move_previous)

-- vim way: ; goes to the direction you were moving.
-- vim.keymap.set({ "n", "x", "o" }, ";", tstextobj_move.repeat_last_move)
-- vim.keymap.set({ "n", "x", "o" }, ",", tstextobj_move.repeat_last_move_opposite)

-- Make builtin f, F, t, T also repeatable with ; and ,
vim.keymap.set({ "n", "x", "o" }, "f", tstextobj_move.builtin_f)
vim.keymap.set({ "n", "x", "o" }, "F", tstextobj_move.builtin_F)
vim.keymap.set({ "n", "x", "o" }, "t", tstextobj_move.builtin_t)
vim.keymap.set({ "n", "x", "o" }, "T", tstextobj_move.builtin_T)

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 13, 2023

The consistency tests all pass. However note that currently it only performs movements in visual mode.

Copy link
Member

@theHamsta theHamsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how this is extensive by using M.last_move outside of this plugin.

Copy link
Member

@theHamsta theHamsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this new functionality in the README?

Thank you a lot for this awesome feature!

@theHamsta
Copy link
Member

@ghostbuster91 do you want us to mention your plugin? I think this feature is small enough to be integrated into our move module, but your plugin could provide configurations for commonly used move plugins (like hop.nvim etc.) since we can't obviously maintain this for more than our move module.

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 14, 2023

@theHamsta Should we make this feature a separate file from move.lua so it is more clear which part is treesitter related and which not?

I can separate this to repeatable_move.lua including all the builtin movements so it's clear why they exist.

@theHamsta
Copy link
Member

@theHamsta Should we make this feature a separate file from move.lua so it is more clear which part is treesitter related and which not?

I can separate this to repeatable_move.lua including all the builtin movements so it's clear why they exist.

Sure, go ahead. I though about this too.

@ghostbuster91
Copy link
Contributor

do you want us to mention your plugin?

@theHamsta That would be cool, thanks!

your plugin could provide configurations for commonly used move plugins (like hop.nvim etc.

yep, that is my plan :)

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 16, 2023

@ghostbuster91 Sure, that's no problem. I'll mention your plugin in the README

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 17, 2023

This is ready

goto_next_end fix
@kiyoon kiyoon force-pushed the feat-movement-repeat branch from 78ca379 to 61b690b Compare January 17, 2023 05:07
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.

3 participants