-
Notifications
You must be signed in to change notification settings - Fork 46
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
Make ;
, ,
repeat keys interoperate with native ;
, ,
#176
Comments
If anyone can solve this (interop with native f/t), I'd be very happy to hear how (I couldn't yet). |
I think this happens also with leap.nvim and flit.nvim. leap then flit -> ; still repeats the leap. Maybe related: ggandor/flit.nvim#29 (comment) |
off the top of my head maybe you could use |
IIRC this works in vim-sneak so there could be some inspiration there |
@ggandor nvim-treesitter/nvim-treesitter-textobjects#359 provides a repeatable movements engine that interops with native In their README, they also mention https://github.com/ghostbuster91/nvim-next as being a more focused and lightweight alternative that provides out of the box Taken directly from the README for nvim-treesitter-textobjectsYou can make the movements repeatable like ; and ,. local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move"
-- Repeat movement with ; and ,
-- ensure ; goes forward and , goes backward regardless of the last direction
vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next)
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous)
-- vim way: ; goes to the direction you were moving.
-- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)
-- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite)
-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f)
vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F)
vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t)
vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T) You can even make a custom repeat behaviour. -- This repeats the last query with always previous direction and to the start of the range.
vim.keymap.set({ "n", "x", "o" }, "<home>", function()
ts_repeat_move.repeat_last_move({forward = false, start = true})
end)
-- This repeats the last query with always next direction and to the end of the range.
vim.keymap.set({ "n", "x", "o" }, "<end>", function()
ts_repeat_move.repeat_last_move({forward = true, start = false})
end) Furthermore, you can make any custom movements (e.g. from another plugin) repeatable with the same keys. This doesn't need to be treesitter-related. -- example: make gitsigns.nvim movement repeatable with ; and , keys.
local gs = require("gitsigns")
-- make sure forward function comes first
local next_hunk_repeat, prev_hunk_repeat = ts_repeat_move.make_repeatable_move_pair(gs.next_hunk, gs.prev_hunk)
-- Or, use `make_repeatable_move` or `set_last_move` functions for more control. See the code for instructions.
vim.keymap.set({ "n", "x", "o" }, "]h", next_hunk_repeat)
vim.keymap.set({ "n", "x", "o" }, "[h", prev_hunk_repeat)
Alternative way is to use a repeatable movement managing plugin such as [nvim-next] Taken from the README for nvim-nextRepeateable movements reborn! By default vim allows repeating default movements like f/F/t/T and others using While I don't use repeating movments often with default motions, I would like to use them with motions like next-treesitter-method, next-diagnostic, next-git-change, etc that comes from many different plugins. This plugin is a repeatable movments engine that other plugins can hook into. You can think of it as of nvim-cmp but for movements. The idea is that other plugins like for example git-signs will expose logic to perform some movement, and then we will wrap it with an adapter and plug into that engine. |
;
, ,
repeat keys don't interoperate with native ;
, ;
;
, ,
repeat keys interoperate with native ;
, ,
@Subjective Interesting project, but it's not interoping with native
I'm not sure what other API we would need to provide other than the |
Interop between leap and flit is doable with some autocommand and expression mapping magic, someone just needs to do it :) |
Seems like vim-sneak just remaps |
If you do Leap then native
f
/t
,;
will repeat the Leap motion rather than the nativef
/t
motion.Workaround: use different bindings for Leap repeat
The text was updated successfully, but these errors were encountered: