Skip to content

Commit eca8108

Browse files
ggandoraaronlifton
andcommitted
docs(readme): add snippet for picking Telescope results
Co-authored-by: Aaron Lifton <aaronlifton@gmail.com>
1 parent 2ec33f2 commit eca8108

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

+43
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,49 @@ vim.keymap.set({'x', 'o'}, '\\', leap_ts)
655655

656656
</details>
657657

658+
<details>
659+
<summary>Shortcuts to Telescope results</summary>
660+
661+
```lua
662+
-- NOTE: If you try to use this before entering any input, an error is thrown.
663+
-- (Help would be appreciated, if someone knows a fix.)
664+
local function get_targets (buf)
665+
local pick = require('telescope.actions.state').get_current_picker(buf)
666+
local scroller = require('telescope.pickers.scroller')
667+
local wininfo = vim.fn.getwininfo(pick.results_win)[1]
668+
local top = math.max(
669+
scroller.top(pick.sorting_strategy, pick.max_results, pick.manager:num_results()),
670+
wininfo.topline - 1
671+
)
672+
local bottom = wininfo.botline - 2 -- skip the current row
673+
local targets = {}
674+
for lnum = bottom, top, -1 do -- start labeling from the closest (bottom) row
675+
table.insert(targets, { wininfo = wininfo, pos = { lnum + 1, 1 }, pick = pick, })
676+
end
677+
return targets
678+
end
679+
680+
local function pick_with_leap (buf)
681+
require('leap').leap {
682+
targets = function () return get_targets(buf) end,
683+
action = function (target)
684+
target.pick:set_selection(target.pos[1] - 1)
685+
require('telescope.actions').select_default(buf)
686+
end,
687+
}
688+
end
689+
690+
require('telescope').setup {
691+
defaults = {
692+
mappings = {
693+
i = { ['<a-p>'] = pick_with_leap },
694+
}
695+
}
696+
}
697+
```
698+
699+
</details>
700+
658701
<details>
659702
<summary>Remote text objects</summary>
660703

0 commit comments

Comments
 (0)