VonHeikemen / searchbox.nvim

Start your search from a more comfortable place, say the upper right corner?

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small Visual mode search / replace issue.

lifer0se opened this issue · comments

This plugin is awesome, excellent job.

I just have a small issue with visual mode.

If the search parameter in either does not exist inside the selected block, I get a lua error. Would it be possible to catch that error and replace it with something cleaner? (for example "Search parameter not found" or something similar)

--Edit: Issue applies to normal mode as well. If the search pattern does not appear in the buffer the lua error pops up.

Also, would it be possible to somehow automatically add the selected text in the search field? As in, if only one word is selected, instead of treating it as a block, use it as a default_value and search the whole buffer.

If the search parameter in either does not exist inside the selected block, I get a lua error. Would it be possible to catch that error and replace it with something cleaner? (for example "Search parameter not found" or something similar)

This is now fixed in 5e176ec. The standard error for search should appear (error code E486).


Also, would it be possible to somehow automatically add the selected text in the search field?

Yes it is. You need to map this in visual mode.

y<cmd>lua require('searchbox').replace({default_value = vim.fn.getreg('"')})<CR>

Due to limitations on the input, It can't handle newlines well or even the escape sequence \n. So whatever you have selected, must be one line.

To get word under the cursor (without visual mode) you do this.

<cmd>lua require('searchbox').replace({default_value = vim.fn.expand('<cword>')})<CR>

All of this works in any kind of search, not just replace.

Works perfectly! Thanks a lot for the quick fix and the default_value tip :)