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())

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


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')

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.