fzf 显示预览窗口

注意
本文最后更新于 2024-05-15,文中内容可能已过时。

可以让 fzf 显示预览窗口功能,使用快捷键 ctrl-f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --preview '(highlight -O ansi {} || cat {}) 2> /dev/null | head -500'"

## fzf : Ctr-f -------------------------------------------------
# .zshrc example
function __fsel_files() {
  setopt localoptions pipefail no_aliases 2> /dev/null
  eval find ./ -type f -print | fzf --reverse -m "$@" | while read item; do
    echo -n "${(q)item} "
  done
  local ret=$?
  echo
  return $ret
}

function fzf-vim {
    selected=$(__fsel_files)
    if [[ -z "$selected" ]]; then
        zle redisplay
        return 0
    fi
    zle push-line # Clear buffer
    BUFFER="nvim $selected";
    zle accept-line
}
zle -N fzf-vim
bindkey "^f" fzf-vim
setopt no_nomatch ## 处理:zsh: no matches found
setopt GLOB_DOTS  ## copy .dotfile: https://unix.stackexchange.com/questions/89749/cp-hidden-files-with-glob-patterns
william 支付宝支付宝
william 微信微信
0%