MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
807 stars 23 forks source link

Quick way to jump back to Search input from results? #287

Closed alex35mil closed 2 weeks ago

alex35mil commented 2 weeks ago

Is there a way to quickly jump back to Search input (or other input fields) from search results?

On other note, I'm on Dvorak and I don't use hjkl at all, so navigation is a bit convoluted. It would be great to expose api to configure navigation keymaps.

MagicDuck commented 2 weeks ago

hi @alex35mil , you can add those types of keybinds easily like so:

vim.api.nvim_create_autocmd('FileType', {
  group = vim.api.nvim_create_augroup('grug-far-keymap', { clear = true }),
  pattern = { 'grug-far' },
  callback = function()
    -- jump back to search input by hitting left arrow in normal mode:
    vim.keymap.set('n', '<left>', function()
      vim.api.nvim_win_set_cursor(vim.fn.bufwinid(0), { 3, 0 })
    end, { buffer = true })
   -- ... whatever other keybinds you like :)
  end,
})

The only other "navigation keymaps" are already configurable (openNextLocation / openPrevLocation): https://github.com/MagicDuck/grug-far.nvim/blob/b7c2b28e49d55ff71cd9bb3ad19a2021316510d8/lua/grug-far/opts.lua#L166 Also, openPrevLocation and gotoLocation accept number counts if you like that kind of nav, but there is nothing qwerty specific 😄

MagicDuck commented 2 weeks ago

note: if you use the latest, you will have to -1 the line number, eg:

vim.api.nvim_win_set_cursor(vim.fn.bufwinid(0), { 2, 0 })

due to a recent change to support https://github.com/MagicDuck/grug-far.nvim/issues/285

alex35mil commented 2 weeks ago

Works for me, thanks!