LoginSignup
11
14

More than 5 years have passed since last update.

作業効率化ツール fzfのおすすめ

Last updated at Posted at 2019-01-20

こちらの記事を参考に僕もfzfを使い始めました。
「おい、peco もいいけど fzf 使えよ」
https://qiita.com/b4b4r07/items/9e1bbffb1be70b6ce033

一年程fzf使いましたが、作業効率がめちゃくちゃ良くなったので(5倍くらい)僕のオススメのfzf使用方法をざっくり紹介します。
zshを使っています!

Chromeのブックマーク検索でfzf使う

ブックマーク検索をfzfで検索するスクリプトを見つけたので使ってみたらすごく便利でした。
適当にurlをbookmarkに保存して、cuiでbを押すとあいまい検索ですぐブックマークを開けるようになりました。

見つけたスクリプト
https://gist.github.com/junegunn/15859538658e449b886f

僕は上記スクリプトをクローンしてzplugでスクリプトパスを通しています。
https://github.com/rainbow23/dotfiles/blob/develop/fzf.sh

zplugの設定箇所
https://github.com/rainbow23/dotfiles/blob/develop/source.sh#L58-L62

source.sh
zplug "rainbow23/73236d896399ca7ee68b8b3900ae39e0", \
  ¦ from:gist, \
  ¦ as:command, \
  ¦ use:b.rb, \
  ¦ rename-to:chrome_bookmarks_with_fzf.rb

CUIでコマンド忘れたときにfzfで簡単に思い出して実行しよう

僕の場合、gitコマンドをよく忘れるのでその度にググっていました。
でもeasy-onelinerでtxtに記載しておけば簡単に思い出して実行できるようになりました。
CUIではこれ無しには作業できないくらいに便利です。

b4b4r07さんのリポジトリをクローンして自分がよく使うコマンドをeasy-oneliner.txtを記載しています。
https://github.com/rainbow23/easy-oneliner
僕はctrl-jjで起動するように変更しています。
https://github.com/rainbow23/easy-oneliner/blob/master/easy-oneliner.zsh#L7

gitコマンド記載の抜粋
https://github.com/rainbow23/easy-oneliner/blob/master/easy-oneliner.txt#L145-L180
[]の中に説明を書いておけば、すぐ思い出せるようにできました。覚えたコマンドを可視化できて良いです。

easy-oneliner.txt
  [githubとアクセス確認] ssh -T git@github.com
  [git conflictで使用 ファイル名を指定必要] git checkout --theirs @
  [git conflictで使用 ファイル名を指定必要] git checkout --ours @
  [git ローカルブランチが特定のリモートブランチを追跡するように設定 追跡させたいローカルブランチにcheckout済み] git branch --set-upstream-to=origin/@
  [git remoteに存在せず、localに存在するブランチを削除] git fetch --all --prune !
  [git ブランチ削除] git branch --delete @
  [git config --global user.email myname@example.com] git config --global user.email @
  [git config --global user.name "My Name"] git config --global user.name @
  [git setting] git config --list !
  [git 設定] git config --global --list !
  [git 設定] git config --local --list !
  [git branch --move <古いブランチ名> <新しいブランチ名>] git branch --move @
  [git リモートリポジトリの変更] git remote set-url origin @
  [git リモートリポジトリのURL確認] git remote -v !
  [git リモートリポジトリの追加] git remote add origin @
  [git 追跡ブランチを指定してプッシュ] git push -u origin @
  [git ローカルrefとリモートrefを比較しローカルが最新なら強制push] git push --force-with-lease
+ [git ローカルをリモートにプッシュする] git push --set-upstream origin @
  [git ブランチ作成してチェックアウト] git checkout -b @
  [git チェリーピック] git cherry-pick @
  [git remote-tracking branches] git branch --remotes !
  [git remote-tracking branches and local branches] git branch --all !
  [git 直前のコミット内容を修正する] git commit --amend !
  [git リベースを対話式で実行] git rebase -i HEAD@
  [git プッシュ] git push !
  [git プル] git pull !
  git clone @
  git log !
  git log --stat !
  git log --graph !
  git log --oneline !
  git reset --hard !
  git reset --mixed !
  git diff --staged !
  git add -u !
  git commit -m "@"
  : git #################################################################################################################

CUIでフォルダ移動をさくさくする

cdで移動する時、過去移動履歴からあいまい検索移動できます。
CUIの移動が苦にならないのでめちゃくちゃ便利になりました。
https://github.com/b4b4r07/enhancd

vimでfzfを使う

vimで開発されている人にオススメです。
vimで検索する時、fzfのあいまい検索してファイルを開く、文字検索できるとメチャクチャ便利です。
fzfはvimプラグインが用意されているのでそちらを使います。

vim設定はこちらを参考にすれば出来ました↓
https://github.com/junegunn/fzf#as-vim-plugin

僕のvim設定のfzf記述箇所↓
https://github.com/rainbow23/dotfiles/blob/develop/_vimrc#L281-L365

僕のfzf設定箇所から普段使用している所を抜粋しました。

_vimrc
Plug 'junegunn/fzf.vim'

 if has("mac")
      set rtp+=~/.fzf
  elseif has("unix")
      set rtp+=~/.fzf
  endif

  let g:fzf_action = {
    \ 'ctrl-t': 'tab split',
    \ 'ctrl-x': 'split',
    \ 'ctrl-v': 'vsplit' }

let mapleader = "\<Space>"

  nnoremap [fzf] <Nop>
  nmap <Leader>f [fzf]

nnoremap [fzf]m :<C-u>FZFMru<CR>
  nnoremap [fzf]f :<C-u>Files<CR>
  " git ls-files
  nnoremap [fzf]g :<C-u>GFiles<CR>
  " git staus
  nnoremap [fzf]G :<C-u>GFiles?<CR>
  nnoremap [fzf]b :<C-u>Buffers<CR>
  nnoremap [fzf]h :<C-u>History<CR>
  " list tabs
  nnoremap [fzf]a :<C-u>Ag<CR>
  nnoremap [fzf]l :<C-u>Lines<CR>
  nnoremap [fzf]s :<C-u>Search<CR>
  nnoremap [fzf]S :<C-u>SearchFromCurrDir<CR>

  command! -bang -nargs=* FZFMru call fzf#vim#history(fzf#vim#with_preview())

  command! -bang -nargs=? GFiles
  \ call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(), <bang>0),

  command! -bang -nargs=? -complete=dir Files
    \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)

  command! -bang -nargs=* Search
    \ call fzf#vim#grep(
    \   'ag --nogroup --column --nocolor ^ $(git rev-parse --show-toplevel main)', 1,
    \   <bang>0 ? fzf#vim#with_preview('up:60%')
    \           : fzf#vim#with_preview('right:hidden', '?'),
    \   <bang>0)

  command! -bang -nargs=* SearchFromCurrDir
    \ call fzf#vim#grep(
    \   'ag --nogroup --column --nocolor ^ $(pwd)', 1,
    \   <bang>0 ? fzf#vim#with_preview('up:60%')
    \           : fzf#vim#with_preview('right:hidden', '?'),
    \   <bang>0)

上記設定で下が一番便利でした。
gitのrootフォルダからファイル内の文字検索からファイルをctrl-tでタブで開く、ctrl-vで縦分割できます。

_vimrc
 nnoremap [fzf]s :<C-u>Search<CR>

  command! -bang -nargs=* Search
    \ call fzf#vim#grep(
    \   'ag --nogroup --column --nocolor ^ $(git rev-parse --show-toplevel main)', 1,
    \   <bang>0 ? fzf#vim#with_preview('up:60%')
    \           : fzf#vim#with_preview('right:hidden', '?'),
    \   <bang>0)

超ざっくりですがfzfのおすすめツールを紹介しました!

11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14