echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.45k stars 171 forks source link

`goto_left` and `goto_right` for next/last variants #973

Closed simonmandlik closed 2 weeks ago

simonmandlik commented 2 weeks ago

Contributing guidelines

Module(s)

mini.ai

Description

It would be great if it was possible specify where to jump to with next/last variants, e.g. g]n). This would be especially useful with search_method = cover.

echasnovski commented 2 weeks ago

Thanks for the suggestion!

My first instinct is that it adds too even more complexity to already overcrowded config.mappings. Implementation-wise this should be pretty straightforward, but will also add documentation and testing burden (both to mappings and underlying exported implementation function).

Also while I do agree that four g{[,]}{n,l} are the right choice of mapping keys for this, they don't look too ergonomic on a standard QWERTY keyboard.

So my suggestion would be to make mappings manually. With something like this:

local map_nextlast_motion = function(lhs, side, search_method)
  local rhs = function()
    MiniAi.move_cursor(side, 'a', vim.fn.getcharstr(), { search_method = search_method, n_times = vim.v.count1 })
  end
  local desc = 'Go to ' .. side .. ' side of ' .. search_method .. ' textobject'
  vim.keymap.set({ 'n', 'x', 'o' }, lhs, rhs, { desc = desc })
end

map_nextlast_motion('g[n', 'left', 'next')
map_nextlast_motion('g]n', 'right', 'next')
map_nextlast_motion('g[l', 'left', 'prev')
map_nextlast_motion('g]l', 'right', 'prev')

Closing as not planned.