ctrlpvim / ctrlp.vim

Active fork of kien/ctrlp.vim—Fuzzy file, buffer, mru, tag, etc finder.
ctrlpvim.github.com/ctrlp.vim
Other
5.55k stars 260 forks source link

Setting initial mode of `CtrlPLastMode`? #620

Open ChristianTackeGSI opened 1 year ago

ChristianTackeGSI commented 1 year ago

I like CtrlPLastMode! But in a new editing session, it starts out with the default Files mode, which I (currently) use rarely. I use Buffer first and then MRU. So I would like to set the initial mode of LastMode to Buffer. Is this possuble?

I even tried things like call ctrlp#switchtype(0), call ctrlp#setlines(0), or call ctrlp#call("s:setlines_pre", -1). But they either fail with an error or set the mode of the next LastMode invocation somewhat wrong.

tacahiroy commented 11 months ago

Currently, the plugin doesn't provide a way of changing the default mode for the CtrlPLastMode. Also, there is no API to update the ControlP mode triggered last time.

But to achieve the goal, you can implement your version of CtrlPLastMode like this:

function! s:my_last_mode(argv) abort
   let s:lm = get(s:, 'lm', 'buf')
   cal ctrlp#init(s:lm, { 'args':  a:argv })
   let s:lm = -1
endfunction
com! -n=? MyLastMode cal <SID>my_last_mode(<q-args>)

Hope this helps.

ChristianTackeGSI commented 11 months ago

This seems to work nicely for me! Thanks!

Could this be added to some docs? Maybe as an example on how to customize things? (Or is it already and I missed it?)