diff options
| author | Volodymyr Kot <volodymyr.kot.ua@gmail.com> | 2021-04-23 16:24:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-23 18:24:09 +0300 |
| commit | 712de3e18237323a979b4fd256703e2edfaddf2f (patch) | |
| tree | 43abbb86063cff6cc4eea62b51d49835a70de99f /lua/telescope/builtin/internal.lua | |
| parent | a28999574efb7a0d5bddb2e7eb543ff7d4cf14b4 (diff) | |
feat: add search history picker (#769)
Co-authored-by: Volodymyr Kot <vkot@palantir.com>
Diffstat (limited to 'lua/telescope/builtin/internal.lua')
| -rw-r--r-- | lua/telescope/builtin/internal.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index cab145d..5164245 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -297,6 +297,36 @@ internal.command_history = function(opts) }):find() end +internal.search_history = function(opts) + local search_string = vim.fn.execute('history search') + local search_list = vim.split(search_string, "\n") + + local results = {} + for i = #search_list, 3, -1 do + local item = search_list[i] + local _, finish = string.find(item, "%d+ +") + table.insert(results, string.sub(item, finish + 1)) + end + + pickers.new(opts, { + prompt_title = 'Search History', + finder = finders.new_table(results), + sorter = conf.generic_sorter(opts), + + attach_mappings = function(_, map) + map('i', '<CR>', actions.set_search_line) + map('n', '<CR>', actions.set_search_line) + map('n', '<C-e>', actions.edit_search_line) + map('i', '<C-e>', actions.edit_search_line) + + -- TODO: Find a way to insert the text... it seems hard. + -- map('i', '<C-i>', actions.insert_value, { expr = true }) + + return true + end, + }):find() +end + internal.vim_options = function(opts) -- Load vim options. local vim_opts = loadfile(utils.data_directory() .. path.separator .. 'options' .. |
