endflow.net blog

/* programming and programming */

Customize the order of FuzzyFinder’s mode switching

with 2 comments

/* What is this? */

This is a patch for FuzzyFinder to customize the order of FuzzyFinder’s mode switching.

fuzzyfindermod

FuzzyFinder is a vim plugin to search with fuzz word and open quickly. It have several modes and changes search domain by current mode. You can switch the mode without leaving FuzzyFinder’s mini-buffer if you press Ctrl+l (next mode) or Ctrl+o (previous mode).

However, I want to customize the order of switching. So I did.

/* Install */

Please apply following patch or overwrite actual plugin file with this applied version. The target version of FuzzyFinder is 2.6.

*** oldfuzzyfinder.vim	2008-05-14 18:51:39.203125000 +0900
--- newfuzzyfinder.vim	2008-05-14 18:50:52.531250000 +0900
***************
*** 362,368 ****
  " FUNCTION: CORE FUNCTIONS: ============================================= {{{1
  "-----------------------------------------------------------------------------
  function! s:GetAvailableModes()
!   return filter(values(g:FuzzyFinderMode), 'exists(''v:val.mode_available'') && v:val.mode_available')
  endfunction

  "-----------------------------------------------------------------------------
--- 362,378 ----
  " FUNCTION: CORE FUNCTIONS: ============================================= {{{1
  "-----------------------------------------------------------------------------
  function! s:GetAvailableModes()
!   let modes = keys(g:FuzzyFinderMode)
!   let r_order = reverse(copy(g:FuzzyFinderOptions.Base.switch_order))
!   for mode_name in r_order
!     call remove(modes, index(modes, mode_name))
!     call insert(modes, mode_name)
!   endfor
!   let list = []
!   for m in modes
!     call add(list, g:FuzzyFinderMode[m])
!   endfor
!   return filter(list, 'exists(''v:val.mode_available'') && v:val.mode_available')
  endfunction

  "-----------------------------------------------------------------------------
***************
*** 1436,1441 ****
--- 1446,1453 ----
  let g:FuzzyFinderOptions.Base.key_next_mode = ''
  " [All Mode] This is mapped to switch to the previous mode.
  let g:FuzzyFinderOptions.Base.key_prev_mode = ''
+ " [All Mode] This is the order for mode switching.
+ let g:FuzzyFinderOptions.Base.switch_order = ['File', 'FavFile', 'Dir', 'MruFile', 'Tag', 'MruCmd', 'TaggedFile', 'Buffer']
  " [All Mode] This is mapped to temporarily switch whether or not to ignore
  " case.
  let g:FuzzyFinderOptions.Base.key_ignore_case = ''

/* Usage */

You get new option g:FuzzyFinderOptions.Base.switch_order if you apply this patch.

" [All Mode] This is the order for mode switching.
let g:FuzzyFinderOptions.Base.switch_order = ['File', 'FavFile', 'Dir', 'MruFile', 'Tag', 'MruCmd', 'TaggedFile', 'Buffer']

You just write mode name to switch_order you want to show by priority. For instance,

let g:FuzzyFinderOptions.Base.switch_order = ['Buffer', 'File', 'MruFile']

I set like that.

switch_order option doesn’t affect mode enable/disable. So you use mode_available option for that. FYI, you don’t need to write all of enable mode name into switch_order option. That is you write only mode name you want to show by priority.

/* Details */

The type of variable g:FuzzyFinderMode that used on mode switching is dictionary.

let g:FuzzyFinderMode = { 'Base' : {} }
let g:FuzzyFinderOptions = { 'Base':{}, 'Buffer':{}, 'File':{}, 'MruFile':{}, 'MruCmd':{}, 'FavFile':{}, 'Dir':{}, 'Tag':{}, 'TaggedFile':{}}

You know, the order of item doesn’t keep because it is converted to list by values function.

function! s:GetAvailableModes()
  return filter(values(g:FuzzyFinderMode), 'exists(''v:val.mode_available'') && v:val.mode_available')
endfunction

/* Conclusion */

I hit on an idea. To simplify starting of FuzzyFinder, it prepare new command “:FuzzyFinder” and open with first mode of specified order when it was called.

And one more thing, I want to show which FuzzyFinder mode I’m using now into the prompt. That’s mean

File>

or

Buf>

instead of actual prompt uses “>”.

This is my first time of reading vim script. However, It’s easy to read and modify for me. like a JavaScript.
Of course, I think because the code of FuzzyFinder is beautiful.

Thank you for your great work, ns9tks!

enjoy vim & FuzzyFinder! ;)

Written by kuy

May 16th, 2008 at 3:28 am

Posted in Uncategorized

Tagged with , , ,

2 Responses to 'Customize the order of FuzzyFinder’s mode switching'

Subscribe to comments with RSS or TrackBack to 'Customize the order of FuzzyFinder’s mode switching'.

  1. はじめまして、FuzzyFinderを作っている者です。
    パッチを書いてしまうくらい気に入ってもらえてうれしいです。ありがとうございます。
    新しいバージョンで切り替えの順番を指定できるようにしました。
    パッチを取り込ませてもらうか悩んだんですが、各モードごとに ‘order’ オプションを持たせて、それをキーに並び順を決定するように実装しました。(単に趣味の問題です。)

    それとプロンプトの件ですが、2文字以上のプロンプトの場合、などで一部削除されたときに、それが「入力された文字列」か「プロンプトの一部」かを判定する方法が思いつかなくて、1文字固定のプロンプトにしたという経緯があります。
    今はウィンドウをさらに垂直分割してモード名を表示するのはどうかなあと、検討中です。

    ns9tks

    17 Jul 08 at 22:48

  2. Appreciate it for helping out, great info. “Riches cover a multitude of woes.” by Menander.

    Adrianna

    19 Oct 11 at 21:55

Leave a Reply