0

I have tried to use FZF to filter my (last) commands. The first function works well and retrieves the list of my last commands. When I select a command, it triggers my HandleCommand function but goes to the wrong position sometimes. Strangely, it doesn't seem to be deterministic(at times the correct one, other times +1 or +3).

Do you know why?

function! GetCommands()
    let lines=[]
    let nu=histnr("cmd")
    for i in range(1,nu)
        let lines+=[histget("cmd",i)]   
    endfor
    return lines
endfunction
function! HandleCommand(item)
    let lines=Getcommands() 
    let pos=index(lines, a:item)-1
    call feedkeys("q::".string(pos)."\<CR>")
endfunction
nnoremap <silent> <C-a>c :call fzf#run({'source': GetCommands(),'sink': function('HandleCommand'),'options': '-m'} )<CR>
  • BTW, I tried to search for the item and it all happens too fast for my editor (oni), so it says item not found. Maybe it is too fast also in this case. Although I don't see how this would happen. – eyal karni May 27 at 20:21
0

I still don't know why, but this seems to solve it. It is a nice way to search for commands, so recommended.

function! HandleCommand(item)
    call feedkeys("q:")
    call feedkeys("G?\\V".escape(a:item,'\/?')."\<CR>")
endfunction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.