My current solution is:
....
skim-hist= ory() {
=C2=A0 origquery=3D\${BUFFER}
=C2=A0 # output=3D\$(history 1 -1= | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact)=C2=A0 # output=3D\$(fc -ln 1 -1 | sk --tac --no-sort --exact)
=C2=A0 nu= m=3D\$(fc -l 1 -1 | sk --tac --no-sort --exact | rg -o '^[ ]*([0-9]*)[ ]= *' -r '\$1')

=C2=A0if [ -n "\$num" ]; then
= =C2=A0 =C2=A0 BUFFER=3D\$(fc -ln \$num \$num)
=C2=A0 else
=C2=A0 =C2=A0 = BUFFER=3D\$origquery
=C2=A0 fi

=C2=A0 # CURSOR=3D\$#BUFFER
=C2= =A0 # zle redisplay
}

zle =C2=A0 =C2=A0 -N =C2=A0 ski= m-history
bindkey '^R' skim-history
....

=
Please let me know how can i make it better.

On Thu, Jul 7, 2022 = at 12:40 PM Ahmad Ismail <ismail7= 83@gmail.com> wrote:
The way fzf do it is

=
....
fzf-history-widget() {
=C2=A0 local selected n= um
=C2=A0 setopt localoptions noglobsubst noposixbuiltins pipefail no_al= iases 2> /dev/null
=C2=A0 selected=3D( \$(fc -rl 1 | perl -ne 'pri= nt if !\$seen{(/^\s*[0-9]+\**\s+(.*)/, \$1)}++' |
=C2=A0 =C2=A0 FZF_DE= FAULT_OPTS=3D"--height \${FZF_TMUX_HEIGHT:-40%} \$FZF_DEFAULT_OPTS -n2..= ,.. --tiebreak=3Dindex --bind=3Dctrl-r:toggle-sort,ctrl-z:ignore \$FZF_CTRL_= R_OPTS --query=3D\${(qqq)LBUFFER} +m" \$(__fzfcmd)) )
=C2=A0 local re= t=3D\$?
=C2=A0 if [ -n "\$selected" ]; then
=C2=A0 =C2=A0 num= =3D\$selected[1]
=C2=A0 =C2=A0 if [ -n "\$num" ]; then
=C2=A0= =C2=A0 =C2=A0 zle vi-fetch-history -n \$num
=C2=A0 =C2=A0 fi
=C2=A0 f= i
=C2=A0 zle reset-prompt
=C2=A0 return \$ret
}
zle =C2=A0 =C2= =A0 -N =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fzf-history-widget
bindk= ey -M emacs '^R' fzf-history-widget
bindkey -M vicmd '^R'= ; fzf-history-widget
bindkey -M viins '^R' fzf-history-widget....

but I want to do it with skim instead of fzf= .

On Thu, Jul 7, 2022 at 11:56 AM Ahmad Ismail <ismail783@gmail.com> wro= te:
My history file looks like:

....
: 165684= 6180:0;mint-vm
: 1657092275:4;g d fpull
: 1657092331:0;stow-dotfiles<= br>: 1657092447:0;fd --hidden --ignore-file .gitignore --base-directory=3D&= quot;\$HOME/.dotfiles/.common-dotfiles-buggy-nemo-bookmarks" --type l -= -type f | sd ^. \$HOME | xargs -I{} rm {}\

: 1657092530:0;fd --hidden= --base-directory=3D"\$HOME/.dotfiles/.common-dotfiles-buggy-nemo-bookm= arks" --type l --type f | sd ^. \$HOME | xargs -I{} rm {}\
stow --ta= rget=3D"\$HOME" --dir=3D"\$HOME/.dotfiles" --no-folding -= -restow .common-dotfiles-buggy-nemo-bookmarks\

: 1657092737:0;for i = in "\${array[@]}"\
do\
=C2=A0\
=C2=A0\
=C2=A0\
\
done
: 165= 7092752:15;array=3D( https://cinnamon-spices.linuxmint.com/appl= ets/view/83\
=C2=A0https://cinnamon-spices.linuxmint.co= m/applets/view/106\
=C2=A0https://cinnamon-spices.linux= mint.com/applets/view/222\
=C2=A0https://cinnamon-spice= s.linuxmint.com/applets/view/238\
=C2=A0https://cinnamo= n-spices.linuxmint.com/applets/view/284\
https://cinnamon-= spices.linuxmint.com/applets/view/303 )\
\
for i in "\${array= [@]}"\
do\
=C2=A0\
=C2=A0\
\
done
....
=

I am working on a widget for fuzzy search history.

....
skim-history() {
=C2=A0 origquery=3D= \${BUFFER}
=C2=A0 output=3D\$(history -1 1 | sd '^[ ]*[0-9]*[ ]*' = '' | sk --tac --no-sort --exact)

=C2=A0 if [ \$? -eq 0 ]; the= n
=C2=A0 =C2=A0 BUFFER=3D\$output
=C2=A0 else
=C2=A0 =C2=A0 BUFFER= =3D\$origquery
=C2=A0 fi

=C2=A0 CURSOR=3D\$#BUFFER
}

zle = =C2=A0 =C2=A0 -N =C2=A0 skim-history
bindkey '^R' skim-history
....

In `history -1 1 | sd '^[ ]*= [0-9]*[ ]*' '' | sk --tac --no-sort --exact`, sd is used instea= d of sed, which=C2=A0just removes numbers from the beginning. However, it m= esses things up if the command is multi-line.

What= I found is, the only way zsh history=C2=A0parsing works correctly is if I = use something like !NUM, to get the history. How can I edit my zle extensio= n to do that?

Another option is (if previous fails= ), do not save multi line commands in history. How can I do that?

--000000000000eed65405e334fa75--