telescope-frecency.nvim icon indicating copy to clipboard operation
telescope-frecency.nvim copied to clipboard

Using `<Tab>` instead of `<C-n>` does not work

Open smjonas opened this issue 4 years ago • 8 comments

When I open frecency with :Telescope frecency, advancing to the next item with <Tab> or to the previous item with <S-Tab> does not work; only <C-n> and <C-p> work.

I am used to pressing <Tab> in Telescope windows so I am not sure why this does not work. Also I saw these lines in frecency.lua which indicate that pressing <Tab> should work:

  vim.api.nvim_buf_set_keymap(
    state.picker.prompt_bufnr,
    "i",
    "<Tab>",
    "pumvisible() ? '<C-n>'  : '<C-x><C-u>'",
    { expr = true, noremap = true }
  )
  vim.api.nvim_buf_set_keymap(
    state.picker.prompt_bufnr,
    "i",
    "<S-Tab>",
    "pumvisible() ? '<C-p>'  : ''",
    { expr = true, noremap = true }
  )

smjonas avatar Oct 04 '21 15:10 smjonas

also having problems with this, ill post here if i find a solution

52617365 avatar Apr 11 '22 06:04 52617365

ditched the whole plugin and started using harpoon instead

52617365 avatar Apr 14 '22 10:04 52617365

I also noticed this. trying to overwrite the mappings to allow for tab like this also does not work:

frecency = {
	mappings = {
		i = {
			["<Tab>"] = "move_selection_worse",
			["<S-Tab>"] = "move_selection_better",
		},
	},
},

chrisgrieser avatar Oct 02 '23 13:10 chrisgrieser

Yes, this is a spec by this code on current build.

https://github.com/nvim-telescope/telescope-frecency.nvim/blob/4bdd9bafc7ac2c6fed03e92efac1e6b4632eda28/lua/frecency/picker.lua#L252-L253

I think it is good if these <Tab>, <S-Tab> are customizable. 🤔

delphinus avatar Oct 02 '23 21:10 delphinus

@chrisgrieser Yeah, there is something going on with key binds in frecency. My default key binds are not passed through like other telescope-extensions. I use this function to multiselect files and open them all. Works with other extensions like live_grep with args. I even added the mappings under frecency extension. No luck on either method for key mapping with frecency, but works with live_grep_args

  local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr)
  local multi = picker:get_multi_selection()
  if not vim.tbl_isempty(multi) then
    require("telescope.actions").close(prompt_bufnr)
    for _, j in pairs(multi) do
      if j.path ~= nil then
        vim.cmd(string.format("%s %s", "edit", j.path))
      end
    end
  else
    require("telescope.actions").select_default(prompt_bufnr)
  end
end
telescope.setup({
...
  mappings = {
    n = {
     ["<CR>"] = select_one_or_multi,
    }
 }
})
extensions = {
    live_grep_args = {},
    frecency = {
      mappings = {
        n = {
          ["<CR>"] = select_one_or_multi,
          ["<c-c>"] = require("telescope.actions").close,
        },
     }
  }
}

phortonssf avatar Oct 26 '23 19:10 phortonssf

Hot fix:

~/.local/share/nvim/lazy/telescope-frecency.nvim/lua/frecency/picker.lua:267

function Picker:set_prompt_options(bufnr)
  vim.bo[bufnr].completefunc = "v:lua.require'telescope'.extensions.frecency.complete"
  -- vim.keymap.set("i", "<Tab>", "pumvisible() ? '<C-n>' : '<C-x><C-u>'", { buffer = bufnr, expr = true })
  -- vim.keymap.set("i", "<S-Tab>", "pumvisible() ? '<C-p>' : ''", { buffer = bufnr, expr = true })
end

teocns avatar Jan 27 '24 12:01 teocns

@teocns If you have hotfix, please do a PR? 🙏

That way it gets fixed for everyone, the rest of us can use your fork until the fix is merged.

chrisgrieser avatar Feb 02 '24 13:02 chrisgrieser

Just pushed a fork with the fix.

@chrisgrieser a PR with upstream may not be reasonable since the hotfix removes autocompletion bindings completely. Might consider to open a PR implementing keymaps configuration via .setup()

teocns avatar Feb 02 '24 13:02 teocns