Trying to use Explore with BufNew

6 views
Skip to first unread message

Jeenu

unread,
Nov 12, 2008, 3:58:21 AM11/12/08
to vim_use
Hi,

I'm trying to use Explore with BufNew auto-command so that I get a
browser whenever I create a new buffer. I did:

aucmd BufNew * Explore

But I don't see Explore command working when I create a new buffer.
All I see is an empty buffer. :au BufNew command does list Explore
but.

BufNew
*.svg setf xml|set matchpairs=<:>
*.gmk setf make
*.make setf make
* Explore

What might be going wrong?

Thanks
Jeenu

Charles Campbell

unread,
Nov 13, 2008, 11:17:19 AM11/13/08
to vim...@googlegroups.com
Well, its au or autocmd. May I suggest trying "BufEnter" instead of
"BufNew"?

Regards,
Chip Campbell

Jeenu

unread,
Nov 13, 2008, 1:02:16 PM11/13/08
to vim_use
The problem with using BufEnter is that I see Explore running on every
other buffer. I.e. I don't see any file contents, but all buffers
would be filled with directory and file listing.

Actually the reason I want this auto command is that I don't need to
type the full path to start editing it. Instead, I thought I would
say :new and I can just browse and pick the file to edit.

Thanks
Jeenu

On Nov 13, 9:17 pm, Charles Campbell <Charles.E.Campb...@nasa.gov>
wrote:

Charles Campbell

unread,
Nov 13, 2008, 2:20:10 PM11/13/08
to vim...@googlegroups.com

Perhaps if you try...

au BufEnter * if line("$") == 1 && getline(1) == "" | Explore | endif

Regards,
Chip Campbell


Jeenu

unread,
Nov 13, 2008, 7:48:30 PM11/13/08
to vim_use
Yup. That seems to work.

Just wondering though -- why doesn't BufNew work? Because of the way
netrw is written?

Thanks
Jeenu

On Nov 14, 12:20 am, Charles Campbell <Charles.E.Campb...@nasa.gov>

Ben Schmidt

unread,
Nov 14, 2008, 7:56:41 AM11/14/08
to vim...@googlegroups.com
> au BufNew * Explore

Hmmm. I expect this doesn't work because the autocommand fires when the
buffer is being created but isn't necessarily put in a window yet, which
obviously is needed for :Explore.

> Actually the reason I want this auto command is that I don't need to
> type the full path to start editing it. Instead, I thought I would
> say :new and I can just browse and pick the file to edit.

Perhaps just get in the habit of using :Sex instead of :new?

And/or use some cabbrev magic?

Ben.

Charles Campbell

unread,
Nov 14, 2008, 9:49:57 AM11/14/08
to vim...@googlegroups.com
Ben Schmidt wrote:
>> au BufNew * Explore
>>
>
> Hmmm. I expect this doesn't work because the autocommand fires when the
> buffer is being created but isn't necessarily put in a window yet, which
> obviously is needed for :Explore.
>
[snip]

That sounds like it could be the case. I wish there was a timing-based
list of events in the docs. In autocmd.txt, under "autocommand-events",
there's an almost-timing-based list, but BufEnter and BufNew are way
down the list. Anyway, when I tried running Jeenu's BufNew triggering
of Explore with netrw's debugging enabled -- well, it doesn't appear
that netrw was even called.

Regards,
Chip Campbell

Tony Mechelynck

unread,
Nov 14, 2008, 2:26:15 PM11/14/08
to vim...@googlegroups.com
On 13/11/08 19:02, Jeenu wrote:
> The problem with using BufEnter is that I see Explore running on every
> other buffer. I.e. I don't see any file contents, but all buffers
> would be filled with directory and file listing.
>
> Actually the reason I want this auto command is that I don't need to
> type the full path to start editing it. Instead, I thought I would
> say :new and I can just browse and pick the file to edit.
>
> Thanks
> Jeenu

Don't you ever create a new file from scratch? Or use an empty buffer
for things which you want to use temporarily but never even write to
disk? I often do: when I want to paste into a program other than Vim
some character which I don't know how to produce with my admittedly
versatile but not universal Belgian keyboard, for instance the French œ
(oe) digraph which you just saw, or the "vulgar" ¼ ⅕ ¾ fractions, I open
a [No Name] buffer in a new split-window in Vim, type the required
characters there using digraphs, keymaps, or even |i_CTRL-V-digit|, and
bring them back over the clipboard. Then :q! is my friend to close the
temporary split window. No need to wake up netrw in all that. When I do
want a directory listing, I use ":new ./" or maybe ":sv $VIMRUNTIME",
IOW I explicitly "edit a directory".

If you want the current directory, or the directory of the current file,
you don't need to type its full path anyway:

current directory:
:new ./
directory of the current file:
:new %:p:h
your home directory:
:new ~/
etc.


Best regards,
Tony.
--
ARTHUR: (as the MAN next to him is squashed by a sheep) Knights! Run away!
Midst echoing shouts of "run away" the KNIGHTS retreat to cover with
the odd
cow or goose hitting them still. The KNIGHTS crouch down under cover.
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

Jeenu

unread,
Nov 15, 2008, 12:20:24 PM11/15/08
to vim_use
I browse code at work; and for that specific use, I wouldn't create
any new files. Rather, I keep opening files (even though I've tags and
cscope) by their names.

One fine day I thought I'll use Explorer, and noticed that it doesn't
work in the way I expected it to. And I thought I'll make a post and
take help finding out what's going wrong. Of course there are more
than one way to do things, and it's just that I happened to try it
this way :)

> current directory:
> :new ./
> directory of the current file:
> :new %:p:h
> your home directory:
> :new ~/
> etc.

Thanks for this. I was kind of stuck with Explorer didn't explore
further.

Jeenu

On Nov 15, 12:26 am, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:

Andy Wokula

unread,
Nov 19, 2008, 7:04:48 AM11/19/08
to vim...@googlegroups.com
Jeenu schrieb:

I don't know what the BufNew event is good for, but it gives me crap:

augroup foo
au!
au BufNew * call AddSomeText()
augroup end

func! AddSomeText()
put = 'Text added from BufNew event!'
endfunc
" EOF


:new

modifies text in the old window (gVim 7.1.315).

--
Andy

Ben Schmidt

unread,
Nov 19, 2008, 7:23:42 AM11/19/08
to vim...@googlegroups.com
> I don't know what the BufNew event is good for, but it gives me crap:
>
> augroup foo
> au!
> au BufNew * call AddSomeText()
> augroup end
>
> func! AddSomeText()
> put = 'Text added from BufNew event!'
> endfunc
> " EOF
>
>
> :new
>
> modifies text in the old window (gVim 7.1.315).

I believe that's as expected:

:help BufNew

> NOTE: When this autocommand is executed, the
> current buffer "%" may be different from the
> buffer being created "<afile>".

Ben.

Reply all
Reply to author
Forward
0 new messages