Open shibisuriya opened 7 months ago
Hmm.. the prompt buffer is using buftype='prompt'
and by design it only works on a single line basis. What you're trying to do is probably possible if all newline characters were converting to their escape characters on paste. This would require overwriting the default paste behavior.
But still live_grep
(which is what I assume you're trying to use), doesn't support multi-line search by default. You can pass an option to enable it but i don't know how common of a need something like this is...
Also what is command+v? is that p
remapped?
1) I don't know if I have remapped command-v to p, but pressing the 'p' key pastes the text in the default register to the buffer.
2) What is the way to convert all newline character line to their escape sequence equalient when pasting text into telescope input?
3) I understand that it doesn't work by default, I would like to know what settings should I apply to telescope.nvim to make this possible.
Thank you.
I am using kickerstarter.nvim, this is my config => https://github.com/shibisuriya/nvim/blob/main/init.lua, I have just made slight config to kickerstarter.nvim...
What is the way to convert all newline character line to their escape sequence equalient when pasting text into telescope input?
This doesn't exist in telescope. Maybe we can add it? I don't feel strongly about it. But it seems like p
to paste into the prompt buffer has some quirks to it due to how vim handles prompt buffers so I'm feeling a little shaky about building things around the idea of pasting into the prompt buffer.
I understand that it doesn't work by default, I would like to know what settings should I apply to telescope.nvim to make this possible.
With live_grep
and grep_string
, you can pass --multiline
to the additional_args
option for those pickers. :h telescope.builtin.live_grep
I am using this...
vim.keymap.set('n', '
Doesn't work...
Can you be more descriptive about what's not working?
Remember, you still can't just paste a multiline block into the buffer. But --multiline
will let you search like foo\nbar
Running into the same issues. Can't seem to paste using os clipboard or p in normal mode. Would love to see this feature!
@jamestrew Technically the function\n should grep the two entires in the file... But it doesn't...
Is there any work around for this, I feel like this is a very basic and essential function for any text editor....
I am unable to copy a bunch of html lines from chrome's inspect and search for them in the codebase... I am switching to vs code for this purpose then coming back to nvim to continue work...
@jamestrew Technically the function\n should grep the two entires in the file... But it doesn't...
you need to escape the parentheses. function\(\)\n
. This works for me with --multiline
.
With the way telescope uses a prompt-buffer, this isn't a trivial problem for telescope I think.
We're kind of limited to a single line prompt, which disallows literal newlines (need to convert \n
to \\n
) but interaction between --multiline
and --fixed-strings
(to allow for not escaping regex special chars), creates a ton of compatibility issues.
I think we can have a workaround for pasting, but the multiline search is a bit tricky to get cleanly currently.
Not saying this won't ever be possible with telescope but there might be existing neovim plugins that handle this workflow better. Sorry.
workaround for pasting
require("telescope").setup({
defaults = {
mappings = {
n = {
["p"] = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local text = vim.fn.getreg('+'):gsub("\n", "\\n") -- which register depends on clipboard option
current_picker:set_prompt(text, false)
end,
},
},
},
})
@shibisuriya @jamestrew I don't think it's a good way, but it works.
local function live_grep_visual()
local saved_reg = vim.fn.getreg('a')
local saved_regtype = vim.fn.getregtype('a')
vim.cmd('normal! "ay')
local text = vim.fn.getreg('a')
vim.fn.setreg('a', saved_reg, saved_regtype)
require('telescope.builtin').live_grep({
additional_args = {'--multiline'},
default_text = text:gsub('\n', '\\n'):gsub('([%(%).%%%+%-%*%?%[%]%^%$%\\%{%}%|])', '\\%1'):gsub('\\\\n', '\\n'),
})
end
return {
'nvim-telescope/telescope.nvim',
tag = '0.1.8',
dependencies = {'nvim-lua/plenary.nvim', 'sharkdp/fd'},
config = function()
vim.keymap.set('v', '<leader>ft', live_grep_visual, {noremap = true, silent = true})
end
}
With this solution you can select one or more lines in visual mode and search for them using <leader>ft
. The "--fixed-strings" option is not used, but all "special characters" are escaped.
The only "problem" is that if you perform a search containing 3 lines, the result will appear three times. By the way, if anyone has a solution to group these three results into one, I'm interested.
sorry for my bad English
Thank you @ArnaudDelgerie!! This works, but it is becoming annoying when I am working on a huge codebase, if my search query contains 3 lines of text, the same result is appearing thrice...
@jamestrew is there any way to convert 3 results into 1? Also are there any plugins that your recommend for this workflow alone (searching multi line strings in a codebase)...
@shibisuriya
is there any way to convert 3 results into 1?
there is, I think this PR will address this but it's been pending a neovim 0.2 release so it won't be available for a while I don't think https://github.com/nvim-telescope/telescope.nvim/pull/2536
Also are there any plugins that your recommend for this workflow alone (searching multi line strings in a codebase)...
I'm not aware of any that will let you just paste a multiline text into a search. Maybe try grug-far? This issue might have some answers https://github.com/MagicDuck/grug-far.nvim/issues/198
Description
I have copied a multiline text using 'yit', this yanks everything that is written within a
in my case... I want to search the content using telescope to know if this piece of code exists somewhere else as well in the codebase or not... I am using kickerstarter.nvim btw.Neovim version
Operating system and version
macos montery v12.5
Telescope version / branch / rev
checkhealth telescope
Steps to reproduce
Expected behavior
No response
Actual behavior
I want be able to search multiline text that was copied using telescope.nvim.
Minimal config