3

I want to write a mapping that does feedkeys(":cd " . getcwd()), waits for me to edit the directory and then press enter, and then runs a command such as :Rg from the fzf plugin.

I tried doing this:

function! Rg_choose_dir()
    call feedkeys(":cd " . getcwd())
    :Rg
endfunction

but that has the effect of :Rg with the argument to feedkeys as the pattern. How can I get the behaviour I want?

1 Answer 1

6

You might be able to make this work with feedkeys, but it's usually hard/brittle to do so.

I would recommend using something input(':cd ', getcwd(), 'dir') to get the directory as input (with directory completion and getcwd() as the default), run the cd, and then do the :Rg:

execute 'cd' input(':cd ', getcwd(), 'dir')
Rg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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