-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find next occurrence of selected text? #2661
Comments
If you open a search prompt, the selected text should automatically appear so you can press enter to automatically search, and then press Ctrl-n to find the next occurrence. Not the most efficient -- it's probably possible to write a small plugin that you can bind to a keybinding that automatically does it. |
I select text and press CTRL-F, the search prompt appears and shows: "Find (regex):", but my selected text is not there. Thank you! o) |
@tbone2k-git Yes, v2.0.8 is pretty old, the feature was added in v2.0.10. @zyedidia Actually there already is a plugin https://github.com/dmaluka/micro-search allowing more efficient searching for the selected text with a single key press. Also it allows searching for the word under cursor with a single keypress, without the need to select this word. Moreover, it also allows searching for the word with a mouse click on this word, i.e. even without the need to position the cursor before searching. But this feature depends on the PR #2605 which is still not merged. |
@dmaluka
Anyway, thank you! It's good to have learned about the plugins in general! o) |
Yep, it cannot be installed officially yet, but if you put search.lua into ~/.config/micro/plug/search it means you effectively "installed" it, i.e. it should already work for you. (The search-on-right-click feature will not work though, it requires recompiling micro with #2605 pulled, basically that's the reason I haven't made the plugin official yet. But search via Alt-s key press should work.) |
Hey! o) I got it working now, I had the actual lua file called "micro-search.lua" due to testing and trying around. Renaming (again) to "search.lua" made it work. Probably the lua file needs to be named like the parent folder, not sure, but great! o) Alt-s is jumping to next occurrence, very perfect.. o) I immediately tried "Shift + Alt +s" to "find previous occurrence".. it does not work, looking at the script.. it's obvious why, it's not implemented yet, maybe I can add this myself. o) Thank you both for helping! o) EDIT: I think jumping from current word/selection to next/previous occurrence by a simple key stroke is basic functionality these days, do you know why it is not built in yet? Is it due to special "micro" spirit of micro or something? o) |
For the record, it should work with "micro-search.lua" as well. The file name can be arbitrary, it only needs to have .lua extension. I've just checked that after renaming to "micro-search.lua" it works for me, both with the newest micro and with 2.0.8, so I have no idea why didn't it work for you.
Yeah, that would be useful.
No one cared much enough to implement it as built in? Personally I'm fine with having it in a plugin. BTW actually I almost never use this Alt-s search myself anyway, instead I use search via right mouse button click on a word, since it allows me to quickly search for a word no matter where the text cursor currently is. |
Yeah, obviously no one cared much enough.. o) Linux tools make me wonder at times, many are super nerdy and have an overkill on switches and functionality, but then there is a lot of stuff with unexpectedly limited functionality - especially on the desktop. Often it seems there is more focus on design and hiding complexity than on being useful and feature rich. I find desktop filemanagers and file pickers especially poor. Often there is no text input to be able to copy/paste a path and everything defaults to showing huge icons e.g., this is quite a contrast to the very functional, but minimal eyecandy on the command line approach. And then there is "sed", which does not know about non-greedy regex in 2022. How is that possible? o) I am no long term linux user, still finding my way and.. anyway.. getting offtopic.. o) I like to keep my hands on the keyboard when working with text, so I prefer a shortcut right there to navigate/search. Everone is different I guess, which is fine! o) Thank you so much, I learned something new, have a nice weekend! o) |
@tbone2k-git I wrote small plugin which redefines Probably if would help you too: I just put it in local micro = import("micro")
local config = import("micro/config")
local buffer = import("micro/buffer")
local util = import("micro/util")
local regexp = import("regexp")
function findUp(bp)
if bp.Cursor:HasSelection() then
bp:FindPrevious()
else
if not util.IsWordChar(util.RuneAt(bp.Buf:LineBytes(bp.Cursor.Y), bp.Cursor.X)) then
return false
end
bp.Cursor:SelectWord()
local search = "\\b"..util.String(bp.Cursor:GetSelection()).."\\b"
bp:Search(search, true, false)
bp:FindPrevious()
end
return true
end
function findDown(bp)
if bp.Cursor:HasSelection() then
bp:FindNext()
else
if not util.IsWordChar(util.RuneAt(bp.Buf:LineBytes(bp.Cursor.Y), bp.Cursor.X)) then
return false
end
bp.Cursor:SelectWord()
local search = "\\b"..util.String(bp.Cursor:GetSelection()).."\\b"
bp:Search(search, true, true)
end
return true
end
function init()
config.TryBindKey("Ctrl-p", "lua:findword.findUp", true)
config.TryBindKey("Ctrl-n", "lua:findword.findDown", true)
end
|
Hello I have the exact same problem, however Ctrl N and Ctrl P doesn't seem to work for me, no plugin, every settings to default don't work. I tried to make sure they are binded with TryBindKey but it doesn't work either. I don't think its the terminal or the shell because I have the exact same behaviour with cool-retro-term alacritty xterm zsh and bash. |
@BrianNormant as a first step, you can use |
I tried micro and I think like it - especially for using "today's standards" of key bindings.
It makes switching editors, environments and operating systems a lot easier. o)
On thing I missed:
How do you search/find text, which is currently selected (to easily find next occurrence e.g.)?
Is this not possible yet? Is there a key binding I can add (I did not find any) - any hints appreciated! o)
Thank you! o)
The text was updated successfully, but these errors were encountered: