fisadev/vim-ctrlp-cmdpalette

Prefer previously used choices

Opened this issue · 4 comments

First of all, thanks for the awesome plugin!

There is a single problem which still bothers me comparing to ST command palette. Here is an example of usage:

  1. I open CmdPalette and write "buf".
  2. The first result I receive is "CtrlPBufTag".
  3. I scroll up to "buffer" command and hit Enter two times to execute the command.

Now, the next time I repeat this, the resullt will be the same (i.e. "CtrlPBufTag" instead of "buffer" will be found first). In Sublime Text, however, it remembers the command I have chosen and makes it the first result for the subsequent searches.

Is it possible to implement something like this in CtrlP?

That's true, it bothers me too.
As it is implemented, I couldn't define that behaviour in this plugin, because it's just a provider of data for CtrlP, which has the logic for filtering and choosing matches. But let me investigate on the CtrlP side, and if it can't be done then we could open an issue on that project.

bsuh commented

It seems that CtrlP doesn't reorder the data, only filters it. Here's a simple diff for prioritizing recently used commands for the current vim session.

diff --git a/autoload/ctrlp/cmdpalette.vim b/autoload/ctrlp/cmdpalette.vim
index 2826029..ee18218 100644
--- a/autoload/ctrlp/cmdpalette.vim
+++ b/autoload/ctrlp/cmdpalette.vim
@@ -91,6 +91,8 @@ func! ctrlp#cmdpalette#accept(mode, str)
   if g:ctrlp_cmdpalette_execute == 1
     call feedkeys("\<CR>", 'n')
   endif
+  call remove(s:cmdpalette_commands, index(s:cmdpalette_commands, a:str))
+  call insert(s:cmdpalette_commands, a:str)
 endfunc

It removes the command from the list and reinserts it in the beginning.

I think the actual enhancement should have a command history file, so ordering of commands can be preserved across sessions. I would work on it and make a pull request, but my vimscript-fu is weak right now.

seems reasonable to me to do this simple change to remember used commands, will implement it, thanks for the idea and code!

As for having a file to preserve ordering across sessions, I'll do it later, not today, and probably not before pyconar 2014 :) (knee deep in conf related work, hehe).

Done!