zsh has a feature (auto_cd) where just typing the directory name will automatically go to (cd) that directory. I’m curious if there would be a way to configure zsh to do something similar with file names, automatically open files with vim if I type only a file name?
zsh has a feature (auto_cd) where just typing the directory name will automatically go
Share
There are three possibilities I can think of. First is suffix aliases which may automatically translate
to
after you do
. But you need to define this alias for every file suffix. It is also processed before most expansions so if
matches same files as
*.psit won’t open anything.Second is command_not_found handler:
. But this does not work for absolute or relative paths, only for something that does not contain forward slashes.
Third is a hack overriding accept-line widget:
. The above alters the history (I can show how to avoid this) and is rather hackish. Good it does not disable suffix aliases (
whence '*.ps'returns the value of the alias), I used to think it does. It does disable autocd though. I can avoid this (just|| test -d $FILEafterwhencetest), but who knows how many other things are getting corrupt as well. If you are fine with the first and second solutions better to use them.