Feature request: Navigate up 'n' directories
alxtlm opened this issue · 4 comments
I often find myself doing commands like this
cd ../../../../../
Is there a shortcut I can use that will cd ../ n times?
z 5
On zsh you can do
cd ....
And it will jump back 3 directories.
On zsh you can do
cd ....
Are you using a global alias to do that, like
alias -g ....='../../..'
?
@alxtlm, I recommend you try the ZSH-LOVERS rationalise-dot
method:
rationalise-dot() {
if [[ $LBUFFER = *.. ]]; then
LBUFFER+=/..
else
LBUFFER+=.
fi
}
zle -N rationalise-dot
bindkey . rationalise-dot
If you put that in your .zshrc
, then typing ...
expands ../..
on the command line; ....
expands to ../../..
; and so on. Give it a try. If you also use
setopt AUTO_CD
you can just start typing .
repeatedly at the prompt and you won't need to type cd
.
I think that's better than introducing a new behavior for Zsh-z; good to keep these things simple and predictable, right?
On zsh you can do
cd ....Are you using a global alias to do that, like
alias -g ....='../../..'
?
Yes, but I never defined them, and I thought they were defined by zsh itself. Maybe they are added by some plugin, sorry.
Yes, but I never defined them, and I thought they were defined by zsh itself. Maybe they are added by some plugin, sorry.
No problem! It's good for people to see that you can do that, too. Thank you.