You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
After opening an entry from a picker, I often do :Telescope resume and select the next/prev entry and open it. For example,
:Telescope find_files
open the file: /path/to/cwd/foo-01.txt
:Telescope resume
open the next file: /path/to/cwd/foo-02.txt
It is annoying that I need three key presses for this: (1) mapping for :Telescope resume, (2) <C-n>, (3) <CR>. I want to do this with one mapping.
Describe the solution you'd like
I've written a function to do this, but this is too ugly to contribute into telescope.nvim. Can anyone write more simply?
resume_snd_select()
localfunctionget_picker(prompt_bufnr)
localaction_state=require"telescope.actions.state"localactions=require"telescope.actions"localpicker=action_state.get_current_picker(prompt_bufnr)
ifnotpickerthenvim.notify("found no picker", vim.log.levels.WARN)
returnelseifpicker.manager:num_results() <=1thenvim.notify("picker has no entry to open", vim.log.levels.WARN)
actions.close(prompt_bufnr)
ifpicker.initial_mode=="insert" thenvim.api.nvim_feedkeys([[<C-\><C-n>]], "i", true)
endreturnendreturnpickerend---@asynclocalfunctionselect_and_open(picker, change)
localactions=require"telescope.actions"localasync=require"plenary.async"localstart=vim.uv.hrtime()
whiletruedolocaldisplayed=picker.stats.displayedifdisplayedanddisplayed>0thenpicker:move_selection(change)
actions.select_default(picker.prompt_bufnr)
returnelseifvim.uv.hrtime() -start>2*1e9thenvim.notify("cannot get results from picker", vim.log.levels.WARN)
actions.close(picker.prompt_bufnr)
returnendasync.util.sleep(10)
endendlocalfunctionresume_and_select(change)
returnfunction()
vim.api.nvim_create_autocmd("FileType", {
group=vim.api.nvim_create_augroup("resume_and_select", {}),
pattern="TelescopePrompt",
once=true,
callback=function(args)
localpicker=get_picker(args.buf)
ifpickerthenrequire("plenary.async").void(select_and_open)(picker, change)
endend,
})
require("telescope.builtin").resume {}
endend
With this function, I can achieve this feature with example mappings below.
vim.keymap.set(
"n",
"<Leader>fj",
resume_and_select(1),
{ desc="Resume Telescope picker and open the next candidate" }
)
vim.keymap.set(
"n",
"<Leader>fk",
resume_and_select(-1),
{ desc="Resume Telescope picker and open the previous candidate" }
)
Describe alternatives you've considered
telescope.nvim has a similar feature: <C-q> (actions.send_to_qflist). But this only works with file-like entries. For pickers that provides non-file-like entries, such as :Telescope help_tags, send_to_qflist does not work, but resume_and_select() works good.
Sorry, I found User TelescopeResumePost event can handle the time when resuming has been completed. I can omit code considerably, so later I will push PR to add functions to do this.
localfunctionget_picker(prompt_bufnr)
localaction_state=require"telescope.actions.state"localactions=require"telescope.actions"localpicker=action_state.get_current_picker(prompt_bufnr)
ifnotpickerthenvim.notify("found no picker", vim.log.levels.WARN)
returnelseifpicker.manager:num_results() <=1thenvim.notify("picker has no entry to open", vim.log.levels.WARN)
actions.close(prompt_bufnr)
ifpicker.initial_mode=="insert" thenvim.api.nvim_feedkeys([[<C-\><C-n>]], "i", true)
endreturnendreturnpickerendlocalfunctionresume_and_select(change)
returnfunction()
vim.api.nvim_create_autocmd("User", {
group=vim.api.nvim_create_augroup("resume_and_select", {}),
pattern="TelescopeResumePost",
once=true,
callback=function(args)
localpicker=get_picker(args.buf)
ifpickerthenvim.schedule(function()
picker:move_selection(change)
require("telescope.actions").select_default(args.buf)
end)
endend,
})
require("telescope.builtin").resume {}
endend
Is your feature request related to a problem? Please describe.
After opening an entry from a picker, I often do
:Telescope resume
and select the next/prev entry and open it. For example,:Telescope find_files
/path/to/cwd/foo-01.txt
:Telescope resume
/path/to/cwd/foo-02.txt
It is annoying that I need three key presses for this: (1) mapping for
:Telescope resume
, (2)<C-n>
, (3)<CR>
. I want to do this with one mapping.Describe the solution you'd like
I've written a function to do this, but this is too ugly to contribute into telescope.nvim. Can anyone write more simply?
resume_snd_select()
With this function, I can achieve this feature with example mappings below.
Describe alternatives you've considered
telescope.nvim has a similar feature:
<C-q>
(actions.send_to_qflist
). But this only works with file-like entries. For pickers that provides non-file-like entries, such as:Telescope help_tags
,send_to_qflist
does not work, butresume_and_select()
works good.Additional context
:UniteNext
/:UnitePrev
.The text was updated successfully, but these errors were encountered: