5

I installed zsh and oh-my-zsh.

By default, when using tab completion zsh adds a trailing space for non-folder files.

For demonstration I created the following folders/files in a folder named test_files and cded into test_files:

test_files ├── dir1 │   └── file4 ├── dir2 │   └── file5 ├── file1 ├── file11 └── file111 

First, I pressed l, s, Space, Tab, Tab, Tab, *, Enter in turn and got ls dir2/* as the 1st command. Second, I pressed l, s, Space, Tab, Tab, Tab, Tab, *, Enter in turn and got ls file1 * as the 2nd command. Please see the gif picture below:

zsh ls commands

For the 2nd command, since "file1" is not a folder, a space was added between "file1" and "*".

I don't want the space added between "file1" and "*", because when I mean to delete files staring with "file1" in their names I'll possibly press r, m, Space, -, r, f, Space, Tab, Tab, Tab, Tab, *, Enter in turn, and I think the command will be rm -rf file1*, but the command will actually be rm -rf file1 * and sometimes I may press 'y' without noticing the added space, so I may delete all the folders and files by mistake. Please see the gif picture below:

zsh rm command

I used to delete many folders and files by mistake.

I googled many days for removing that space but have not succeed.

I found add-space from zsh document pretty looks what I want, then I tried zstyle ':completion:*' add-space false, but it seems that nonthing changed.

I tried only place the following lines in my .zshrc, it still adds that space:

autoload -U compinit && compinit zmodload -i zsh/complist zstyle ':completion:*' menu select zstyle ':completion:*' add-space false 

If I remove zstyle ':completion:*' menu select, the space is not added, but the cursor won't traverse the folders/files when pressing the tab key, so I want to keep menu select in configs. Please see the gif picture below:

zsh rm command without menu select

I also tried many other configs.

Thanks in advance.

1 Answer 1

1

You can add * to $ZLE_REMOVE_SUFFIX_CHARS.

ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&|*' 

(here appended to the value used by default when the variable is not set)

So the suffix that completion inserts, whether it's / or space be removed when typing * after the selected completion.

1
  • I really really really appreciate it! Commented Mar 15 at 13:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.