How do you change the root of the netrw tree in vim?
Asked Answered
N

7

15

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?

Novosibirsk answered 24/2, 2014 at 19:12 Comment(0)
G
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.

Guttering answered 24/2, 2014 at 20:32 Comment(6)
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.Novosibirsk
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.Guttering
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.Novosibirsk
The Ntree command is new as of January 3rd, 2014; that's why a lot of vaguely-recent installations don't have it.Devonian
so, is there any way to upgrade netrw?Scintillate
@Scintillate 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*.vimGuttering
F
29

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.

Foliaceous answered 24/6, 2016 at 10:9 Comment(1)
This is a fuller answer than the accepted one. Many people will come here looking for the default mapping.Scibert
G
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.

Guttering answered 24/2, 2014 at 20:32 Comment(6)
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.Novosibirsk
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.Guttering
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.Novosibirsk
The Ntree command is new as of January 3rd, 2014; that's why a lot of vaguely-recent installations don't have it.Devonian
so, is there any way to upgrade netrw?Scintillate
@Scintillate 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*.vimGuttering
R
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

Ripley answered 16/3, 2018 at 9:58 Comment(0)
P
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?

Pedagogy answered 25/2, 2014 at 9:16 Comment(1)
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.Novosibirsk
P
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.

Pierre answered 16/4, 2014 at 14:31 Comment(0)
C
-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.

Crofter answered 30/3, 2020 at 9:13 Comment(1)
Interesting, but this changes Vim's current directory, not Netrw's browsing directory.Moraine
T
-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  
Turbulent answered 26/2, 2014 at 1:17 Comment(1)
The question is about netrw, not NERDTree.Daumier

© 2022 - 2024 — McMap. All rights reserved.