I need to write a function that when executed it opens colon command and paste some stuff on to it and let user edit it before executing the command.

for example

function! EditRelativePath()

  :e expand("%")


so i'm expecting the above code to start a prompt like

:e src/user/index.js

but it does not simply work, please advice, thanks.

1 Answer 1


Try this:

:call feedkeys(':e ' . expand('%'))

See :help feedkeys() for more details.

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.