Search code examples
linuxzsh

Call compinit manually in zsh as part of a bindkey function


So, I have setup my .zshrc to have a basic level of syntax checking by creating bindkey lines for basically all character generating keys and pointing them to respective functions that both generate the character and then call the syntax checker.

It is otherwise working perfectly, however I want to apply it to tab so that it will take into account $BUFFER changes from compinit, however calling compinit manually within the trap_tab function I created doesn't even call compinit.

Any help is much appreciated!

Below is the relevant bit. Just uncomment and recomment the bindkey and zle -N lines. When uncommented, even though compinit is called, I do not receive any autofill options when hitting tab.

# Setup basic config stuff for history size, Vim keybindings, and the like
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt  extendedglob notify
unsetopt nomatch

# Auto-completion (double-tab tab)
zstyle :compinstall filename '/home/terminus/.zshrc'
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select

function trap_tab
{
    compinit
}

#bindkey '  ' trap_tab
#zle -N trap_tab

export EDITOR='vim

Solution

  • Turns out there is no "proper" solution, however at least one guy on GitHub figured out a self-described "hacky" solution which does appear to do what I want, albeit with some additional formatting needed: github.com/Valodim/zsh-capture-completion