I am trying to create an alias that builds upon my previous command.Say I run ag fooAfter looking at the list I want to be able to use those results in vim so I dovim -q<(!! --vimgrep)The alias I want is alias edit-last='vim -q<(!! --vimgrep)'But I can't seem to use !! in my alias. I'm having a hard time finding info about what the !! is, a built-in, an alias
How can I use !! in zsh alias
zsh;alias;command history
!! is history expansion. The first ! starts a history expansion; !! has the event designator meaning the previous command.You can access the command history via the fc and history builtins and via the history variable.Since --vimgrep only makes sense with ag, your alias would be more useful if it applied to the last ag command. You can locate the previous ag command like this:${${(M)history:#ag *}[1]}Furthermore you'll need to inject the --vimgrep into the command.alias edit-last='vim -q<(eval ${${(M)history:#ag *}[1]} --vimgrep)'The last ag command won't make sense anymore if you've changed the current directory. This is difficult to detect. You may want to whitelist acceptable commands instead. This isn't a perfect test of course.edit-last () {  local cmd  setopt local_options extended_glob  for cmd in $history; do    case $cmd in      ((ls|(cvs|git|hg|svn) status)(| *)) :;;      (ag *) vim -q<(eval $cmd --vimgrep); return;;      (edit-last) :;;      (*) echo >&2 The previous ag command is too old.; return 125;;    esac  done}