0

I'm on windows 10 with the Windows subsystem for linux. What I'd like to do with netrw is be able to jump from my home folder in Ubuntu to my home folder in windows. In Ranger I type gh and it takes me to my Ubuntu home folder immediately. I mapped ga to go to my Windows home folder so I can jump to that folder immediately too. Can this be done with vim's netrw without any plugins? I want a shortcut to jump between these two directories:

  • Ubuntu home directory: /home/me
  • Windows home directory: /mnt/c:/users/me
2

Netrw supports bookmarks, which could be used for this. See :h netwr-bookmark:

BOOKMARKING A DIRECTORY         netrw-mb netrw-bookmark netrw-bookmarks

One may easily "bookmark" the currently browsed directory by using     
        mb
[...]
                                                        netrw-:NetrwMB
Addtionally, one may use :NetrwMB to bookmark files or directories.     
        :NetrwMB[!] [files/directories]
CHANGING TO A BOOKMARKED DIRECTORY                      netrw-gb

To change directory back to a bookmarked directory, use    
        {cnt}gb
LISTING BOOKMARKS AND HISTORY           netrw-qb netrw-listbookmark

Pressing "qb" (query bookmarks) will list both the bookmarked directories and
directory traversal history.

So, you can run :NetrwMB /mnt/c:/users/me/ to add it as a bookmark. Use qb to see the list of bookmarks, and note the number (which should be 1 if you haven't added a bookmark yet), and press <number>gb (e.g., 1gb) to go that directory.

Note that the list of bookmarks is kept in a sorted order (not by order of addition). So if you bookmark more directories, the numbers may change.

  • Thanks for the clarification. I added the following to my notes for quick reference: mb to bookmark current directory qb to query bookmarks 1gb to goto bookmark1 2gb to goto bookmark2 bc to close bookmarks – Adrian Nielsen Jun 8 at 14:48

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.