You can use these commands to open the ZSH command's history(When you are in the home or ~ directory) and assume that you know how to use vim or nano :
nano ~/.zsh_history
vim ~/.zsh_history
open ~/.zsh_history
then you can delete the lines you want manually and save the file.
and if your zsh_history list is too long, for convenience use this:
enable mouse move and line numbering in the Vim environment by adding this to .vimrc:
open .vimrc:
vim ~/.vimrc
add these to .vimrc and save it(press ESC, enter ":" , write wq, and press enter):
:set number
set mouse=a
use the mouse to scroll easily in zsh_history by using Vim.
if you want to enable copy in Vim use holding shift on the keyboard.
This function will remove any one line you want from your Zsh history, no questions asked:
# Accepts one history line number as argument.
# Alternatively, you can do `dc -1` to remove the last line.
dc () {
# Prevent the specified history line from being saved.
local HISTORY_IGNORE="${(b)$(fc -ln $1 $1)}"
# Write out history to file, excluding lines that match `$HISTORY_IGNORE`.
fc -W
# Dispose of the current history and read the new history from file.
fc -p $HISTFILE $HISTSIZE $SAVEHIST
# TA-DA!
print -r "Deleted '$HISTORY_IGNORE' from history."
}
If you additionally want to prevent all dc commands from being written to history, add the following in your ~/.zshrc file:
zshaddhistory() {
[[ $1 != 'dc '* ]]
}
Alternatively, for a comprehensive, out-of-the-box solution, use my Zsh Hist plugin.