2

My working directory is /a and I open up netrw with :tabe /b. I now want to change my working directory to /b. I read that :cd<CR> should work but it just does the same thing as typing cd in a buffer (sends me home).

Using netrw v171 and VIM 9.0.749.

1 Answer 1

4

This seems to work:

cd %

which I interpret as: vim thinks that current dir is open file so cd % changes to open dir in netrw.

2
  • This is the only answer that worked in VIM9, but I still don't get why. :help % linked me to some usage of % seemingly unrelated to this answer (•_•)
    – X Zhang
    Commented Nov 21, 2022 at 15:04
  • 1
    I also use vim9. % is the register where the current filename is. In input Ctrl-r % writes current filename. Also, :echo expand('%') echos current filename (and current path in netrw) so I guess cd % expands to cd current_path in netrw.
    – Hunaphu
    Commented Nov 21, 2022 at 17:13

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.