How to get prompt value in telescope.vim?

1k Views Asked by At

When using the live_grep picker in telescope, I would like to be able to map a key to open the current search terms in CtrlSF so I can do a mass search and replace.

How can I pass the search terms to another function?

1

There are 1 best solutions below

0
mmngreco On BEST ANSWER

Not sure if this apply to your problem but I've got the prompt value using this snippet (taken from https://github.com/nvim-telescope/telescope.nvim/issues/2016#issue-1276097274):

        local current_picker = require('telescope.actions.state').get_current_picker(prompt_bufnr)
        local prompt = current_picker:_get_prompt()
        print(prompt)

Context

In case it helps here's my whole function

    local vim_edit_prompt = function(prompt_bufnr)
        local current_picker = require('telescope.actions.state').get_current_picker(prompt_bufnr)
        local prompt = current_picker:_get_prompt()
        local cwd = current_picker.cwd
        actions.close(prompt_bufnr)
        vim.api.nvim_exec(':edit ' .. cwd .. '/' .. prompt, false)
        return true
    end