Simplest ZSH AutoJump
by dugan from LinuxQuestions.org on (#5MXPC)
This is the simplest (and IMHO correct) way to set up an equivalent of autojump in ZSH:
Code:autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default yes
zstyle ':completion:*' recent-dirs-insert always
zstyle ':completion:*:*:cdr:*:*' list-suffixeszstyle
zstyle ':completion:*:*:cdr:*:*' expand prefix suffix
alias j=cdrSee the zshcontrib manpage for the explanation.
The list-suffiszstyle and "expand prefix suffix" options are to get TAB-completion to work if you just enter a substring of a directory in your history and press TAB. It's from here: Moving to zsh, part 5: Completions
Or, if you'd prefer a more FISH-like experience where the CD command is augmented with history completion and everything can complete from the middle of a string:
Code:autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default yes
zstyle ':completion:*' recent-dirs-insert both
zstyle ':completion:*' list-suffixeszstyle ':completion:*' expand prefix suffix
alias cd=cdrMy ZSH setup, btw, is Oh My ZSH with the fzf, history-substring-search, zsh-autosuggestions and zsh-syntax-highlighting plugins. It's pretty typical.
Code:autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default yes
zstyle ':completion:*' recent-dirs-insert always
zstyle ':completion:*:*:cdr:*:*' list-suffixeszstyle
zstyle ':completion:*:*:cdr:*:*' expand prefix suffix
alias j=cdrSee the zshcontrib manpage for the explanation.
The list-suffiszstyle and "expand prefix suffix" options are to get TAB-completion to work if you just enter a substring of a directory in your history and press TAB. It's from here: Moving to zsh, part 5: Completions
Or, if you'd prefer a more FISH-like experience where the CD command is augmented with history completion and everything can complete from the middle of a string:
Code:autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default yes
zstyle ':completion:*' recent-dirs-insert both
zstyle ':completion:*' list-suffixeszstyle ':completion:*' expand prefix suffix
alias cd=cdrMy ZSH setup, btw, is Oh My ZSH with the fzf, history-substring-search, zsh-autosuggestions and zsh-syntax-highlighting plugins. It's pretty typical.