Directory listing in (g)vim

102 views
Skip to first unread message

googler

unread,
Jul 22, 2009, 10:40:16 PM7/22/09
to vim_use
Hi,
I am using the directory listing features of gvim (for example using
the Explore command). I am wondering if there is a way to display the
directory contents in a tree structure, like in Windows Explorer for
example. Currently when I click on a directory name, it will open a
new page and show the contents of this directory. I don't want this --
what I want is, it will just expand the subtree under that directory.
Is such a thing possible in gvim? May be I'm asking for too much, but
it will be nice if this is possible.
In case the above is possible, a great use (or next step) will be to
have a file open in a split window when its name is clicked on the
other window.
Any suggestions? Thanks.

Charles E Campbell Jr

unread,
Jul 22, 2009, 12:41:35 AM7/22/09
to vim...@googlegroups.com
* When looking at a directory, press the "i" key several times until
you get the tree listing style. If you always want that style, put

let g:netrw_liststyle= 3

into your .vimrc .

* let g:netrw_retmap = 1 lets a double-left click return to the
directory menu (you didn't ask, but I thought it of interest)

* let g:netrw_browse_split= 2

Regards,
Chip Campbell


googler

unread,
Jul 22, 2009, 11:52:17 PM7/22/09
to vim_use


On Jul 21, 11:41 pm, Charles E Campbell Jr <drc...@campbellfamily.biz>
wrote:
> googler wrote:
> > Hi,
> > I am using the directory listing features of gvim (for example using
> > the Explore command).

[snip]

> > Any suggestions? Thanks.
>
>  * When looking at a directory, press the "i" key several times until
> you get the tree listing style.  If you always want that style, put
>
>     let g:netrw_liststyle= 3
>
>   into your .vimrc .
>
> * let g:netrw_retmap = 1   lets a double-left click return to the
> directory menu  (you didn't ask, but I thought it of interest)
>
> * let g:netrw_browse_split= 2
>
> Regards,
> Chip Campbell

Wow, this is great! This is why I love vim :)

Ben Fritz

unread,
Jul 23, 2009, 10:29:32 AM7/23/09
to vim_use
There's also the NERD tree plugin, which can replace netrw for local
files:

http://www.vim.org/scripts/script.php?script_id=1658

googler

unread,
Jul 28, 2009, 5:34:31 PM7/28/09
to vim_use


On Jul 21, 11:41 pm, Charles E Campbell Jr <drc...@campbellfamily.biz>
wrote:
I have been using gvim in certain cases as you had suggested. I have a
gvim session up. The left window is a directory listing and the right
window is an open file (opened by pressing 'enter' on one of the file
names on the left window). I pressed the key i a few times for the
left window to get a hierarchical listing. Also, I have set
g:netrw_browse_split to 4. So things are good, except for one annoying
problem. When the cursor is on the left window and I click on the
right window to make it the active window, that does not happen.
Instead what I get is that the directory listing disappears from the
left window and in its place it opens a new file for editing. The name
of this file is the same as the line on which I had clicked on the
right window. Clearly, this is not what I wanted and I have to bring
back the directory listing by doing a :Explore. Usually (while not
listing directory contents), I can click on a window to make it the
active window and it works fine there. Why is it not working in this
case then? How do I avoid this problem? Thanks!

Charles E Campbell Jr

unread,
Jul 28, 2009, 3:20:35 AM7/28/09
to vim...@googlegroups.com
googler wrote:
>
> I have been using gvim in certain cases as you had suggested. I have a
> gvim session up. The left window is a directory listing and the right
> window is an open file (opened by pressing 'enter' on one of the file
> names on the left window). I pressed the key i a few times for the
> left window to get a hierarchical listing. Also, I have set
> g:netrw_browse_split to 4. So things are good, except for one annoying
> problem. When the cursor is on the left window and I click on the
> right window to make it the active window, that does not happen.
> Instead what I get is that the directory listing disappears from the
> left window and in its place it opens a new file for editing. The name
> of this file is the same as the line on which I had clicked on the
> right window. Clearly, this is not what I wanted and I have to bring
> back the directory listing by doing a :Explore. Usually (while not
> listing directory contents), I can click on a window to make it the
> active window and it works fine there. Why is it not working in this
> case then? How do I avoid this problem? Thanks!
>
Hello!

I'm afraid that I'm not seeing this behavior. For one thing:

gvim .
:let g:netrw_browse_split= 4
click on a file with leftmouse button

yields a window with the file contents atop the directory window, not
side by side as you've suggested above. Perhaps you have more options
set? I did this with the following "simple.vimrc":

set nocp
filetype plugin indent on
let g:netrw_browse_split = 4
let g:netrw_liststyle = 3

and using gvim -u simple.vimrc . Anyway, clicking on the directory
window just made it the active one; it didn't select&open a file for
editing. I'm using netrw v136k . What version of netrw are you
using? If its not v136k, may I suggest that you try it out.

(http://mysite.verizon.net/astronaut/vim/index.html#NETRW)

Regards,
Chip Campbell

googler

unread,
Jul 29, 2009, 12:02:42 AM7/29/09
to vim_use


On Jul 28, 2:20 am, Charles E Campbell Jr <drc...@campbellfamily.biz>
wrote:
Yes, if I have g:netrw_browse_split set to 4 and no file is open yet,
by default vim creates a horizontal split window to open a file. To
avoid this, I had already created a vertical split window by :vsp and
after that I'm opening other files on that window. This is actually
one question I had in mind - is it possible to open in vertical split
mode instead of the default horizontal split?

> I did this with the following "simple.vimrc":
>
> set nocp
> filetype plugin indent on
> let g:netrw_browse_split = 4
> let g:netrw_liststyle    = 3
>
> and using   gvim -u simple.vimrc  .  Anyway, clicking on the directory
> window just made it the active one; it didn't select&open a file for
> editing.  I'm using netrw v136k .  What version of netrw are you
> using?  If its not v136k, may I suggest that you try it out.

Perhaps you misunderstood my problem. The left window is directory
listing and the right window is an open file. The left window is
active. Now I click somewhere on the _right_ window wishing to make it
the active window. This makes the directory listing disappear on the
left window and a new file opens up in its place. Assuming the line I
clicked on the right window has "abcdefgh wxyz", the name of the file
that just opened up will be "abcdefgh wxyz".

Actually I'm not very sure with the click -- whether it's going as a
single click or a double click on my computer. You can try double
clicking if you want and see if you get the same thing.

I'm using gvim 7.2, although I'm not sure about the netrw version.
Thanks.

Charles Campbell

unread,
Jul 29, 2009, 10:08:41 AM7/29/09
to vim...@googlegroups.com
googler wrote:
> Perhaps you misunderstood my problem. The left window is directory
> listing and the right window is an open file. The left window is
> active. Now I click somewhere on the _right_ window wishing to make it
> the active window. This makes the directory listing disappear on the
> left window and a new file opens up in its place. Assuming the line I
> clicked on the right window has "abcdefgh wxyz", the name of the file
> that just opened up will be "abcdefgh wxyz".
>
> Actually I'm not very sure with the click -- whether it's going as a
> single click or a double click on my computer. You can try double
> clicking if you want and see if you get the same thing.
>
> I'm using gvim 7.2, although I'm not sure about the netrw version.
>
With that request, I'm now using the following in a file called
"simple.vimrc":

set nocp
filetype plugin indent on

run netrwPlugin.vim


let g:netrw_browse_split = 4

let g:netrw_preview = 1


let g:netrw_liststyle = 3


and gvim -u simple.vimrc -U NONE .

I click on a file, then <ctrl-w>hjjjj (ie. move back to the directory
window,
move down a bit, and then leftmouse click on the right window). The right
window becomes selected; no change in the directory listing window.
Double-clicking doesn't affect this.

Again, I did this with netrw v136k. When you get a directory listing,
on the
second line of the banner at the far right appears (netrw v136k).

Regards,
Chip Campbell

googler

unread,
Jul 29, 2009, 12:59:04 PM7/29/09
to vim_use

On Jul 29, 9:08 am, Charles Campbell <Charles.E.Campb...@nasa.gov>
wrote:
> I click on a file, then  <ctrl-w>hjjjj   (ie. move back to the directory
> window,
> move down a bit, and then leftmouse click on the right window).  The right
> window becomes selected; no change in the directory listing window.
> Double-clicking doesn't affect this.
>

I see.. although I'm consistently observing the behavior that I
mentioned earlier.

> Again, I did this with netrw v136k.  When you get a directory listing,
> on the
> second line of the banner at the far right appears  (netrw v136k).
>

I'm using netrw v132, maybe that is causing the problem?

Thanks for your help on this. It's pretty cool using vim like this, so
I can simultaneously see the directory listing and open any file
easily. I'm thinking of writing some script that will enable
highlighting the name of the file on the directory listing if that
file is currently the active buffer. Planning to start soon whenever I
get some free time. I've never really written any vim script before,
but hoping that this will be interesting.

Btw, is it possible to ask vim to not show the header in a directory
listing? By header I mean the lines starting with " at the top of the
directory listing.

Charles Campbell

unread,
Jul 29, 2009, 1:15:55 PM7/29/09
to vim...@googlegroups.com
googler wrote:
> I'm using netrw v132, maybe that is causing the problem?
>
That version is getting old; I suggest getting v136k:

http://mysite.verizon.net/astronaut/vim/index.html#NETRW

> Thanks for your help on this. It's pretty cool using vim like this, so
> I can simultaneously see the directory listing and open any file
> easily. I'm thinking of writing some script that will enable
> highlighting the name of the file on the directory listing if that
> file is currently the active buffer. Planning to start soon whenever I
> get some free time. I've never really written any vim script before,
> but hoping that this will be interesting.
>

Probably should use the match command in the netrw buffer. Glad you
like netrw!


> Btw, is it possible to ask vim to not show the header in a directory
> listing? By header I mean the lines starting with " at the top of the
> directory listing.
>

Currently the banner cannot be suppressed.

Regards,
Chip Campbell

scott

unread,
Jul 29, 2009, 1:50:19 PM7/29/09
to vim...@googlegroups.com
On Wednesday 29 July 2009 12:15:55 Charles Campbell wrote:
>
> Currently the banner cannot be suppressed.

+1 wishing he could suppress the banner

sc

googler

unread,
Jul 29, 2009, 1:58:17 PM7/29/09
to vim_use


On Jul 29, 12:15 pm, Charles Campbell <Charles.E.Campb...@nasa.gov>
wrote:
Hello, if I have opened directory listing using :Explore and have the
default liststyle set (that is I haven't set g:netrw_liststyle to 3
yet), and then do ":let g:netrw_liststyle=3", it does not change to
hierarchical listing. Until now I had been pressing the i key, so I
didn't notice this. Is this a bug in netrw v132. Do you see this with
v136?

I think it will be nice to have an option to hide the banner. It will
be nice to have it implemented in future version of netrw (are you the
author of this plugin?). Thanks.

Charles Campbell

unread,
Jul 29, 2009, 3:13:43 PM7/29/09
to vim...@googlegroups.com

Changing a variable's value isn't immediately tied to a screen refresh,
as can be the case
when changing a vim option via set. Furthermore, different windows may
have different
liststyles; g:netrw_liststyle acts as a default for a window. The
actual window liststyle is
w:netrw_liststyle. So

let w:netrw_liststyle= 3
<ctrl-L> (which causes a refresh)

will change the listing style. You may note that pressing the "i" key
several times does
not change g:netrw_liststyle (but it does change w:netrw_liststyle).


> I think it will be nice to have an option to hide the banner. It will
> be nice to have it implemented in future version of netrw (are you the
> author of this plugin?). Thanks.
>

The banner is of variable length depending on a few options
(hiding/showing/normal), whether
or not a target directory has been set for copying, etc. I've added
yet-another-option
(g:netrw_banner) which can be used to suppress banner display (v136l).
I hope its obvious
that I haven't had time to test all the side effects of this change.

Regards,
Chip Campbell

scott

unread,
Jul 29, 2009, 3:19:42 PM7/29/09
to vim...@googlegroups.com
On Wednesday 29 July 2009 14:13:43 Charles Campbell wrote:
>
> The banner is of variable length depending on a few options
> (hiding/showing/normal), whether
> or not a target directory has been set for copying, etc. I've
> added yet-another-option
> (g:netrw_banner) which can be used to suppress banner display
> (v136l). I hope its obvious
> that I haven't had time to test all the side effects of this
> change.

for yet another option i find myself hollering yet another round
of thanx! -- this one's very cool -- i've tested it all of one
time and it works great!

sc

scott

unread,
Jul 29, 2009, 3:28:11 PM7/29/09
to vim...@googlegroups.com

on closer inspection i am seeing (or not, actually) the command
line in any window after having used netrw -- i can't see
messages down there either, for example nothing shows up when i
hit <ctrl>-G

sc

scott

unread,
Jul 29, 2009, 4:09:56 PM7/29/09
to vim...@googlegroups.com

another thing i am seeing with it is that the

autocmd BufEnter * lcd %:p:h

i put in vimrc in place of autochdir to avoid the 'fo' problem
seems to have become irrelevant to netrw -- now when i Explore it
is on the directory i was on first when i started the session,
regardless of where i have moved since

i am not complaining, simply reporting -- if you want to take it
off-line for a full round of testing/debugging i'm good with that
too

sc

googler

unread,
Jul 29, 2009, 4:12:50 PM7/29/09
to vim_use
Is this new version v136I already available? In an earlier post, Dr
Chip said that currently there is no option of suppressing the banner,
but now he says there is an option g:netrw_banner. I'm confused.

Charles Campbell

unread,
Jul 29, 2009, 4:34:24 PM7/29/09
to vim...@googlegroups.com
googler wrote:
> Is this new version v136I already available? In an earlier post, Dr
> Chip said that currently there is no option of suppressing the banner,
> but now he says there is an option g:netrw_banner. I'm confused.
>
The version of netrw on my website is my development version.
Consequently it gets updated;
so, versions earlier than v136l (that's an "ell") don't have banner
suppression. Banner suppression,
unfortunately, has side effects. It'll be awhile before they all get
caught.

Regards,
Chip Campbell

scott

unread,
Jul 29, 2009, 4:34:43 PM7/29/09
to vim...@googlegroups.com
On Wednesday 29 July 2009 15:12:50 googler wrote:
> Is this new version v136I already available? In an earlier
> post, Dr Chip said that currently there is no option of
> suppressing the banner, but now he says there is an option
> g:netrw_banner. I'm confused.

it's available if you go to his website:

http://mysite.verizon.net/astronaut/vim/index.html

this is where the bleeding edge netrw can be gotten

if you want a set of scripts that check for a new netrw i can
send them to you, but you'll need bash, python, BeautifulSoup,
wget, and i don't know what else

sc

googler

unread,
Jul 30, 2009, 12:19:21 AM7/30/09
to vim_use


On Jul 29, 9:08 am, Charles Campbell <Charles.E.Campb...@nasa.gov>
wrote:
Hello Dr. Chip, I have some more information on this problem. I do not
see this problem when I run gvim on windows. The problem I was telling
about earlier was on Linux. The netrw version in both cases is v132,
so I don't understand why it appears only in one case and not the
other. Can you tell me of some variables that I can check to find more
about this? Thanks.

Charles Campbell

unread,
Jul 30, 2009, 10:18:13 AM7/30/09
to vim...@googlegroups.com
Well, I'm still advising you to upgrade to the latest netrw. The
upgrade to netrw will go into
your local directory, not the system directory. Since netrw comes as a
vimball, removing it
from your local directories is simple, too (:RmVimball netrw).

(http://mysite.verizon.net/astronaut/vim/index.html#NETRW)

My testing was done on a Linux box (Centos 5.2). Did you try it with the


gvim -u simple.vimrc -U NONE

command I gave? That'll avoid any issues with interfering settings and
other plugins.

Regards,
Chip Campbell

Reply all
Reply to author
Forward
0 new messages