Skip to content
YMK Must be Kidding
Go back

Compatible fzf Plugins Loader

Updated:

每家包起來的位置都不一樣,很麻煩耶!

fzf 好好用

前一陣子又被介紹了一下 fzfvim plugin,真正花點時間了解了一下之後, 發覺到 fzf 本身還能拿來做不少事情,也能取代幾個目前用的 vim plugins, 所以就認真得來設定一番。

除了 fzf 本身之外,也還有很多跟其他程式配合的 plugins,像是 zsh 以及剛剛提到的 vim,都是日常生活中的基礎必需品,所以當然也想要每個 terminal {% fa_inline terminal %} 都一樣啊!

想想看要設定上的環境大概有:

fzf and ohmyzsh

zsh 的管理工具 ohmyzsh 也好好用啊,當然裡面就有寫好的 fzf 的 plugin 了, 在一般的 {% fa_inline linux fab %} 上直接 plugins=(fzf)應該大致上都沒有問題, 但放到其他的環境像是 termux 就 load 不成功了,原因是 plugin 不知道另外裝的 fzf 在哪裡,需要另外指定.

# Set fzf installation directory path
export FZF_BASE=/path/to/fzf/install/dir

指定之後也只是找到 completion.zshkey-bindings.sh 直接 source 而已。 也可以看到就算是 {% fa_inline linux fab %},也還是會包在不同地方,

# Fix fzf shell directory for Archlinux package
if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then
  fzf_shell="${fzf_base}"
else
  fzf_shell="${fzf_base}/shell"
fi
...
source "${fzf_shell}/completion.zsh"
...
source "${fzf_shell}/key-bindings.zsh"

不是很想這樣判斷展開 fzf_base, 反正 fzf 都在 PATH 裡的嘛, 所以就自己改了以上提到的環境都能用的方法。

{% codeblock lang:zsh .zshrc %} for F in (find(find (which fzf | sed ‘s//bin/fzf//share/fzf/’) -name “*.zsh”); do source $F done {% endcodeblock %}

fzf and vim

相同的 vim 也有寫好的 plugin fzf.vim,根據 {% blockquote Arch Wiki Fzf, https://wiki.archlinux.org/index.php/Fzf#Vim %} Vim
The basic Vim plugin is already included within the package and installed to Vim’s global plugin directory. Thus, you don’t need to add anything to your .vimrc to be able to use it. It only provides the FZF command, though. There is an additional Vim plugin made by the author of fzf that defines some convenience functions {% endblockquote %}

本來只要裝 fzf.vim 就可以了,偏偏 anacondafzf 是沒有包進基本的 vim fzf plugin 的,即便是用了 anacondavim 也是沒有, 所以就還是額外指向原本的 upstream 的 fzf 那一個。

{% codeblock lang:vim .vimrc %} ” fzf Bundle ‘junegunn/fzf’ Bundle ‘junegunn/fzf.vim’ map :Buffers map :Files map :Rg! nmap sr :History: nmap s/ :History/ {% endcodeblock %}


Share this post on:

Previous Post
URL Selector in Tmux with Urlscan
Next Post
Blogging with Hexo and Inside Theme