I would like to setup a bindkey to launch a fuzzy search across projects, home directories, files etc... and launch some command depending of the choosen file type.

If the file is a regular file, I would like for now to open it using VIM.

I didn't find what I need (if you have some proposition, I'm hearing!), ao I wrote this script inspired from fzf:

# ALT-C - Fuzzy commands
fzf-project-widget() {
  local cmd="(
    find -L . -mindepth 1
    ghq list
  ) 2> /dev/null"
  setopt localoptions pipefail 2> /dev/null
  local line="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"

  if [[ -z "${line}" ]]; then
    zle redisplay
    return 0

  local project_dir="${HOME}/p/$line"
  [[ -d "${project_dir}" ]] && line=${project_dir}

  if [[ -d "${line}" ]]; then
    cd ${line}
  elif [[ -x "${line}" ]]; then
  elif [[ -f "${line}" ]]; then
    ${EDITOR} ${line}
    echo "Nothing to do for ${line}" && false

  local ret=$?
  zle fzf-redraw-prompt
  return ${ret}
zle     -N    fzf-project-widget
bindkey '\ec' fzf-project-widget

It works but with some edges cases for vim:

  1. If I select a regular file with my fzf key-binding, I will always have this warning: Vim: Warning: Input is not from a terminal
  2. Vim is extremely slow to load the file. It take seconds comparing to nearly instant opening if I use the classic vi <my_file.ext> command.

Am I missing something or maybe there is a much better way than that to achieve what I want?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.