zsh-使用autocd的第一个选项卡完成 [英] zsh - first tab completion with autocd
问题描述
我目前正在从csh切换到zsh,我正在编写.zshrc,试图获取在此新shell中我习惯的所有选项.
I am currently switching from csh to zsh I am writing a .zshrc trying to get all the options I am used to in this new shell.
我使用autocd(只需输入名称即可进入目录(不使用cd命令),我想知道我是否有可能首先提议当前目录中存在的所有文件(例如它在csh中工作).
I use autocd (to go into a directory just typing its name (without the cd command), and I wonder if it is possible that my first propose all the files existing in the current directory (like it's working in csh).
在键入命令之前,只需按一下我的命令行中没有写的任何内容,我就已经习惯了这样一种方式来概述可以打开的文件或可以自动cd"到的目录.
I am quite used to this way of having an overview of the files I can open or directory I can "autocd" into, before typing my command just pressing without anything written in my commandline yet.
现在,当我第一次按下它时,它不会触发任何完成机制,而只是编写一个实际的列表.
Right now when I first press it does not trigger any completion mechanism but it just write an actual tabulation.
我还没有找到任何解决方案,如果有人有任何神奇的选择来获得此结果,请随时启发我!
I did not find any solution yet, and if anyone has any magic options to get this results, feel free to enlighten me!
谢谢
推荐答案
我找到了一种方法!
不需要autocd,尽管zsh中存在此选项
放入您的~/.zshrc
:
I found a way!
No need for autocd, though this option exists in zsh
To put in your ~/.zshrc
:
first-tab() {
if [[ $#BUFFER == 0 ]]; then
BUFFER="cd "
CURSOR=3
zle list-choices
else
zle expand-or-complete
fi
}
zle -N first-tab
bindkey '^I' first-tab
感谢此问题:空行上的zsh制表符完成
因此,按一下Tab键,您将获得"cd"和现有目录.
So press tab once and you will get "cd " and the existing directories.
检出man zshoptions
可能有用的其他现有选项
(setopt menucomplete
对于保存选项卡可能很有用,但也可以更改其他完成方式的行为.)
Checkout man zshoptions
for other existing options which could be useful
(setopt menucomplete
could be useful to save a tab, but change behaviour for other completion as well.)
这篇关于zsh-使用autocd的第一个选项卡完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!