On 2008-10-07, Tony Mechelynck <[EMAIL PROTECTED]> wrote:
> On 07/10/08 16:08, Bob Hiestand wrote:
> > On Tue, Oct 7, 2008 at 8:57 AM, A. S. Budden<[EMAIL PROTECTED]> wrote:
> >> 2008/10/7 Bob Hiestand<[EMAIL PROTECTED]>:
> >>> You could do something like the following (untested):
> >>>
> >>> :auto BufRead * if expand('%') =~ '^/some/directory'|set
> >>> ft=somefiletype|endif
> >> Wouldn't expand('%:p') be better?
> >>
> >> :help expand()
> >
> > I don't think it matters, as the matching is just testing to see if
> > the file name starts with that path.
>
> I think it does, as the problem was that the match was not found when
> typing the filename without a path because the file's directory was
> already current.
>
> Example:
> :lcd /some/dir
> :e filename.ext
>
> then expand('%') is "filename.ext", not "/some/dir/filename.ext". If you
> test (expand('%') =~ '^/some/dir') it'll return 0 i.e. FALSE.
>
> OTOH under the same circumstances expand('%:p') is
> "/some/dir/filename.ext" and it should work.
>
> However, I believe you should test for =~ '^some/dir/' with an ending
> slash, otherwise you'll also find a match for /some/direction/file.txt
For an autocommand pattern there is no need to expand the filename.
See
:help autocmd-patterns
where it says:
2. When there is a '/' in the pattern, Vim checks for a match
against both the short file name (as you typed it) and the
full file name (after expanding it to a full path and
resolving symbolic links).
So the autocommand
auto BufRead /some/directory/* set ft=foo
will be triggered by any of the following:
$ vim /some/directory/myfile
$ cd /some/directory
$ vim myfile
$ cd /some
$ vim directory/myfile
Regards,
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---