In zsh, I know that I can search history with Ctrl+r. However, oftentimes I start to type a command directly at the prompt, but then realize I should be searching history. When I hit Ctrl+r, it brings up a blank history search prompt like this:
Notice how there is text at my prompt but not at the history search prompt. How do I start the history search with the text already in the prompt, so it looks like this:
Best Answer
You can use zle's
history-search
functionality:This binds Up and Down (adjust for your own escape sequences) to a history search, backwards and forwards, based upon what has already been entered at the prompt.
So, if you were to enter "vim" and hit Up, zsh will traverse backwards through your history for only those commands commencing with "vim".
You can additionally have the cursor placed at the end of the line once you have selected your desired command from zsh's history by using the history-search-end function (typically located in
/usr/share/zsh/functions/Zle/
) and appending-end
to the end of each line, like so: