13

The title sums it up, really. I'd like to know how to set the current root of the tree when browsing files using netrw in vim.

Any ideas?

Patrick Bacon
  • 4,490
  • 1
  • 26
  • 33
jabalsad
  • 2,351
  • 6
  • 23
  • 28

7 Answers7

25

You can also use "gn" mapping to change the current directory to the folder under your cursor.

CHANGING TREE TOP netrw-ntree :Ntree netrw-gn {{{2

One may specify a new tree top for tree listings using

    :Ntree [dirname]

Without a "dirname", the current line is used (and any leading depth information is elided). With a "dirname", the specified directory name is used.

The "gn" map will take the word below the cursor and use that for changing the top of the tree listing.

cppcho
  • 393
  • 4
  • 6
9

Per the documentation for netrw, use the ex command

:Ntree [dirname]

Assuming you have netrw installed, one can obtain more information on this using help

:help Ntree

Often times, I will just change the current work directory using the ex command

:cd [dirname]

Next, I start the explorer (ex command again)

:Exp

***Addendum***********

To update your version of netrw, I would just follow the directions that the author, Charles Campbell, posted on www.vim.org.

Patrick Bacon
  • 4,490
  • 1
  • 26
  • 33
  • I don't have Ntree as a valid command and there is nothing in the documentation about it either. W.r.t to using `cd` and then running `Exp`, the explorer always opens the previous explorer window regardless of what my `pwd` is. – jabalsad Feb 24 '14 at 20:44
  • It sounds like you have an older version of netrw. I am unaware of when this feature was packaged with netrw. Perhaps you should look into upgrading netrw. Another option would be to use the ex command, :Exp [dirname] or :Vexp [dirname], and this will provide you with a similar outcome. – Patrick Bacon Feb 24 '14 at 21:10
  • Indeed. Looks like I do not have this feature. I'm using MacVim 7.4 but the feature seems to be available in my terminal vim. – jabalsad Feb 25 '14 at 13:22
  • 1
    The Ntree command is new as of January 3rd, 2014; that's why a lot of vaguely-recent installations don't have it. – Max Cantor Jul 10 '14 at 15:12
  • so, is there any way to upgrade netrw? – vp_arth Nov 22 '14 at 14:48
  • 1
    @vp_arth I updated my answer. Charles Campbell on his notes on installing explains that you need to remove all runtime plugin/netrw*.vim and autoload/netrw*.vim – Patrick Bacon Nov 24 '14 at 05:01
3

quite old thread, but maybe someone find this information useful that currently you can use c to change to current dir.

If you want to always change pwd while browsing around with netrw you could use: let g:netrw_keepdir = 0

mrajner
  • 392
  • 4
  • 9
0

What do you mean by "the current root of the tree"?

Do you want a faster or more deterministic way to browse directories in netrw than the usual --/foo<CR><CR>/bar<CR><CR>/baz<CR><CR>?

Or do you want to be able to open netrw in a specific directory?

Or something else?

romainl
  • 186,200
  • 21
  • 280
  • 313
  • 3
    I've got netrw to show directories using tree format (g:netrw_liststyle=3). The tree has a root at the very top, which is usually the `pwd` when you first start netrw. However, as I explore, I'd like to update the root of the tree, but cannot figure out how to do this. If I close the netrw buffer and reopen it (even when pointing at a specific directory like `:Ex ~/new-directory` then I still get the previous buffer with the same tree root. – jabalsad Feb 25 '14 at 13:18
0

netrw v151 supports changing the treetop (root of tree):

:Ntree [directory]

and one may use the "-" key to have the treetop become the parent of the current tree. See http://www.drchip.org/astronaut/vim/index.html#NETRW for the latest netrw.

user21497
  • 1,061
  • 8
  • 9
-1

As of the doc of netrw, just type cd to make the browsing directoyr the current directory:

*netrw-c* : This map's name has been changed from "c" to cd (see |netrw-cd|).
          This change was done to allow for |netrw-cb| and |netrw-cB| maps.

Note: the doc seems inconsistent, because the quick reference has a line with

 c  Make browsing directory the current directory        |netrw-c|

... but cd works as explained above.

ocolot
  • 718
  • 6
  • 18
-4

You can also press "C" while the cursor is on the directory you'd like to make the current home.

From NerdTree help

" Filesystem mappings~                  |~                                                                                                                                                                                                                                                                                   
" C: change tree root to the            |~                                                                                                                                                                                                                                                                                   
"    selected dir                       |~                                                                                                                                                                                                                                                                                   
" u: move tree root up a dir            |~                                                                                                                                                                                                                                                                                   
" U: move tree root up a dir            |~                                                                                                                                                                                                                                                                                   
"    but leave old root open            |~                                                                                                                                                                                                                                                                                   
" r: refresh cursor dir                 |~                                                                                                                                                                                                                                                                                   
" R: refresh current root               |~                                                                                                                                                                                                                                                                                   
" m: Show menu                          |~                                                                                                                                                                                                                                                                                   
" cd:change the CWD to the              |~                                                                                                                                                                                                                                                                                   
"    selected dir                       |~                                                                                                                                                                                                                                                                                   
" CD:change tree root to CWD  
lsaffie
  • 1,764
  • 1
  • 17
  • 22