questions on netrw

930 views
Skip to first unread message

bill lam

unread,
Jul 2, 2008, 1:11:51 AM7/2/08
to vim...@googlegroups.com
vim7 has netrw build-in and very useful, but I have some troubles in using it,

1. how to hide hidden files/directory (ie, same as Ctrl-h in nautilus), when I
type a, it give some error message I cannot understand.

2. How to browse to other directory and save a file there?

regards,

Charles E Campbell Jr

unread,
Jul 2, 2008, 10:20:24 AM7/2/08
to vim...@googlegroups.com
bill lam wrote:
> vim7 has netrw build-in and very useful, but I have some troubles in using it,
>
> 1. how to hide hidden files/directory (ie, same as Ctrl-h in nautilus), when I
> type a, it give some error message I cannot understand.
>

The message is probably: **warning** (netrw) your hiding list is empty!
Try reading the help: :help netrw-a

You can set the hiding list semi-permanently with

:let g:netrw_list_hide="hiding pattern1,hiding pattern2, ..."

or for the current session with ctrl-h. There's also a built-in
shortcut; use gh . You may need a more up-to-date netrw for that
(v126e is available from my website,
http://mysite.verizon.net/astronaut/vim/index.html#NETRW)


> 2. How to browse to other directory and save a file there?
>

Put cursor atop a directory name (or the ".." to go up a directory).
Press <cr> to browse the directory.
If your g:netrw_keepdir is 1 (the default value), then press "c" to
make the browsed directory vim's current directory.
If your g:netrw_keepdir is 0, then the browsed directory is already
your current directory.
Use regular vim commands to write a file.

Regards,
Chip Campbell

bill lam

unread,
Jul 2, 2008, 11:22:49 AM7/2/08
to vim...@googlegroups.com
Charles E Campbell Jr wrote:
> shortcut; use gh . You may need a more up-to-date netrw for that
> (v126e is available from my website,
> http://mysite.verizon.net/astronaut/vim/index.html#NETRW)

I already used vim7.2a beta, so that gh is available. That command is what I
looked for. However gh also hide ../ and it became impossible to go up to parent
directory without gh again. Is that a bug?

>> 2. How to browse to other directory and save a file there?
>>
> Put cursor atop a directory name (or the ".." to go up a directory).
> Press <cr> to browse the directory.
> If your g:netrw_keepdir is 1 (the default value), then press "c" to
> make the browsed directory vim's current directory.
> If your g:netrw_keepdir is 0, then the browsed directory is already
> your current directory.

I can see that "c" is the key command. BTW should I browse directory using
:Explore or other command? That :Explore means typing alot. I'm lazy :-)

regards,

Charles E Campbell Jr

unread,
Jul 2, 2008, 11:20:35 AM7/2/08
to vim...@googlegroups.com
bill lam wrote:
> Charles E Campbell Jr wrote:
>
>> shortcut; use gh . You may need a more up-to-date netrw for that
>> (v126e is available from my website,
>> http://mysite.verizon.net/astronaut/vim/index.html#NETRW)
>>
>
> I already used vim7.2a beta, so that gh is available. That command is what I
> looked for. However gh also hide ../ and it became impossible to go up to parent
> directory without gh again. Is that a bug?
>

No -- its supposed to hide any file or directory starting with ".", and
obviously that includes "..". You can still use the "-" key.


>
>>> 2. How to browse to other directory and save a file there?
>>>
>>>
>> Put cursor atop a directory name (or the ".." to go up a directory).
>> Press <cr> to browse the directory.
>> If your g:netrw_keepdir is 1 (the default value), then press "c" to
>> make the browsed directory vim's current directory.
>> If your g:netrw_keepdir is 0, then the browsed directory is already
>> your current directory.
>>
>
> I can see that "c" is the key command. BTW should I browse directory using
> :Explore or other command? That :Explore means typing alot. I'm lazy :-)
>

You can use :Explore (or variants) of course; you can also just edit a
directory.

:e DIRECTORY_NAME_HERE

Regards,
Chip Campbell

bill lam

unread,
Jul 2, 2008, 11:52:14 AM7/2/08
to vim...@googlegroups.com
Thanks for confirmation.

I still have some questions,
1. inside the browse window, how to copy the abs path+filename or just the
filename of the item under cursor, like
/home/bill/foo/bar.txt or bar.txt

2. I can see the sort order is different from the locale collating sequence, eg
in ls or nautilus, ordering is
Abbb
a11
Baa

but in netrw. it is
Abbb
Baa
a11

can this be changed?

regards,

Tony Mechelynck

unread,
Jul 2, 2008, 12:25:16 PM7/2/08
to vim...@googlegroups.com
On 07/02/08 17:52, bill lam wrote:
> Thanks for confirmation.
>
> I still have some questions,
> 1. inside the browse window, how to copy the abs path+filename or just the
> filename of the item under cursor, like
> /home/bill/foo/bar.txt or bar.txt
>
> 2. I can see the sort order is different from the locale collating sequence, eg
> in ls or nautilus, ordering is
> Abbb
> a11
> Baa

that is strange. On Linux I've always seen ls placing all uppercase
(even Z) before all lowercase (even a). Let me see... no, "ls -U" will
print its results unsorted ("sorted by directory order") but "man ls" on
my system doesn't show any option for ignore-case sorting.

>
> but in netrw. it is
> Abbb
> Baa
> a11
>
> can this be changed?
>
> regards,

If it can, I don't know how. (And ":help pi_netrw.txt" doesn't show
anything obvious for caseless sorting.)

Remember that on Unix-like OSes, case differences in filenames are
usually significant: ./Makefile is not the same as ./makefile or
./MAKEFILE. Important files usually get capitalized names, such as
README, in order to bring them to the top of the directory listing
(sorted in "machine collating sequence", i.e., 0-9 before A-Z before a-z
etc.)


Best regards,
Tony.
--
Oregano, n.:
The ancient Italian art of pizza folding.

Charles E Campbell Jr

unread,
Jul 2, 2008, 12:35:17 PM7/2/08
to vim...@googlegroups.com
bill lam wrote:
> Thanks for confirmation.
>
> I still have some questions,
> 1. inside the browse window, how to copy the abs path+filename or just the
> filename of the item under cursor, like
> /home/bill/foo/bar.txt or bar.txt
>

Well, the word under the cursor can be obtained with the usual
expand("<cword>").
Netrw's idea of the current directory is: b:netrw_curdir


> 2. I can see the sort order is different from the locale collating sequence, eg
> in ls or nautilus, ordering is
> Abbb
> a11
> Baa
>
> but in netrw. it is
> Abbb
> Baa
> a11
>
> can this be changed?
>

Essentially, the sorting is done by vim's sort command (:help :sort).
However, usual sorting is controlled by the g:netrw_sort_sequence, which
is a variable holding a string of comma-separated patterns. An "*" is a
wildcard, standing for all files or directories that haven't been
matched by any of the other patterns. So you should be able to use it
to obtain the sorting sequence you prefer. The default setting is:
'[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$' , which
gives directories, .h, .c, and .cpp files precedence.

Regards,
Chip Campbell

bill lam

unread,
Jul 2, 2008, 1:01:58 PM7/2/08
to vim...@googlegroups.com
Tony Mechelynck wrote:
> that is strange. On Linux I've always seen ls placing all uppercase
> (even Z) before all lowercase (even a). Let me see... no, "ls -U" will
> print its results unsorted ("sorted by directory order") but "man ls" on
> my system doesn't show any option for ignore-case sorting.

That case-sensitive collating is strange to me too. What is your LC_COLLATE
setting when typing cmd "locale"?

GNU sort should depend on locale, but apparently vim's internal sort doesn't.

regards,

bill lam

unread,
Jul 2, 2008, 1:03:34 PM7/2/08
to vim...@googlegroups.com
>Charles E Campbell Jr wrote:

Thanks for explanation.

regards,

Christian Brabandt

unread,
Jul 2, 2008, 1:27:15 PM7/2/08
to vim...@googlegroups.com
Hi Tony!

On Wed, 02 Jul 2008, Tony Mechelynck wrote:

> that is strange. On Linux I've always seen ls placing all uppercase
> (even Z) before all lowercase (even a). Let me see... no, "ls -U"
> will print its results unsorted ("sorted by directory order") but
> "man ls" on my system doesn't show any option for ignore-case
> sorting.

That depends on your locale. You can specify your sort order by
exporting $LC_COLLATE or $LC_ALL, the latter will override all other
$LC_ variables.

regards,
Christian
--
:wq!

Charles E Campbell Jr

unread,
Jul 2, 2008, 4:25:18 PM7/2/08
to vim...@googlegroups.com
Charles E Campbell Jr wrote:
I've included Yet-Another-Option: g:netrw_sort_options . Basically, its
a string that will be appended to the :sort used in netrw, so one may
use "i", for example, to ignore case. Its in v126f and later.

Regards,
Chip Campbell

Tony Mechelynck

unread,
Jul 2, 2008, 7:47:59 PM7/2/08
to vim...@googlegroups.com
On 07/02/08 19:01, bill lam wrote:
> Tony Mechelynck wrote:
>> that is strange. On Linux I've always seen ls placing all uppercase
>> (even Z) before all lowercase (even a). Let me see... no, "ls -U" will
>> print its results unsorted ("sorted by directory order") but "man ls" on
>> my system doesn't show any option for ignore-case sorting.
>
> That case-sensitive collating is strange to me too. What is your LC_COLLATE
> setting when typing cmd "locale"?

When typing ":lang" in Vim, $LC_COLLATE=C
Outside of Vim, $LC_COLLATE and $LC_ALL are unset in the environment,
$LANG=POSIX, typing "locale" at the shell prompt gives the following:

LANG=POSIX
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=


What are yours?

Case-sensitive collating (of file names, at least) is the Unix norm AFAIK.

>
> GNU sort should depend on locale, but apparently vim's internal sort doesn't.
>
> regards,

Best regards,
Tony.
--
The typewriting machine, when played with expression, is no more
annoying than the piano when played by a sister or near relation.
-- Oscar Wilde

bill lam

unread,
Jul 2, 2008, 9:03:14 PM7/2/08
to vim...@googlegroups.com
Tony Mechelynck wrote:
> LANG=POSIX
> LC_CTYPE=en_US.UTF-8
> LC_NUMERIC="POSIX"
> LC_TIME="POSIX"
> LC_COLLATE="POSIX"
> LC_MONETARY="POSIX"
> LC_MESSAGES="POSIX"
> LC_PAPER="POSIX"
> LC_NAME="POSIX"
> LC_ADDRESS="POSIX"
> LC_TELEPHONE="POSIX"
> LC_MEASUREMENT="POSIX"
> LC_IDENTIFICATION="POSIX"
> LC_ALL=
>
>
> What are yours?

$ locale
LANG=en_HK.UTF-8
LC_CTYPE="en_HK.UTF-8"
LC_NUMERIC="en_HK.UTF-8"
LC_TIME="en_HK.UTF-8"
LC_COLLATE="en_HK.UTF-8"
LC_MONETARY="en_HK.UTF-8"
LC_MESSAGES="en_HK.UTF-8"
LC_PAPER="en_HK.UTF-8"
LC_NAME="en_HK.UTF-8"
LC_ADDRESS="en_HK.UTF-8"
LC_TELEPHONE="en_HK.UTF-8"
LC_MEASUREMENT="en_HK.UTF-8"
LC_IDENTIFICATION="en_HK.UTF-8"
LC_ALL=

HK is Hong Kong. I thought you use a french or dutch locale.

regards,

Tony Mechelynck

unread,
Jul 2, 2008, 9:41:43 PM7/2/08
to vim...@googlegroups.com

Actually, I use the default locale (with messages in English) but a
fr_BE (AZERTY) keyboard. When I worked on mainframes more than 30 years
ago, all computer books were in English. When the first French books
appeared, their terminology sounded "weird" to me and I stayed with
English as much as possible. (I suppose that when the first Chinese and
Japanese computer books appeared, their terminology must have sounded
equally weird to people who had started with English.)

At one time I had to work with a French, and then a Dutch, version of
Windows; I was also learning Vim then and I soon learnt that adding

if has('unix')
language messages C
else
language messages en
endif

at the very start of my vimrc, would bring back my beloved English
messages and menus, in Vim at least :-) ("if" because that was a
double-boot vimrc and both OSes didn't accept the same locales).


Best regards,
Tony.
--
"You've got to have a gimmick if your band sucks."
-- Gary Giddens

Bill McCarthy

unread,
Jul 3, 2008, 12:25:18 AM7/3/08
to Charles E Campbell Jr
On Wed 2-Jul-08 3:25pm -0600, Charles E Campbell Jr wrote:

> I've included Yet-Another-Option: g:netrw_sort_options . Basically, its
> a string that will be appended to the :sort used in netrw, so one may
> use "i", for example, to ignore case. Its in v126f and later.

Very nice - I've added that one to my _vimrc. Thanks!

--
Best regards,
Bill

bill lam

unread,
Jul 3, 2008, 1:17:08 AM7/3/08
to vim...@googlegroups.com

Normally I don't look at hidden files. If it could, please add
yet-another-option for gh that it hides as the default.

regards,

Charles E Campbell Jr

unread,
Jul 3, 2008, 9:49:00 AM7/3/08
to vim...@googlegroups.com
That's already there: g:netrw_list_hide

The "gh" map simply appends or removes the string '\(^\|\s\s\)\zs\.\S\+'
from the g:netrw_list_hide string.

Regards,
Chip Campbell

bill lam

unread,
Jul 3, 2008, 11:08:30 AM7/3/08
to vim...@googlegroups.com

done! I add this line in my vimrc

let g:netrw_list_hide='\(^\|\s\s\)\zs\.\S\+'

regards,

Reply all
Reply to author
Forward
0 new messages