Steven Woody wrote:
> I want to use $vimruntimepath/vimfiles.vim to recognize one of my
> special formatted text file, that file begin with a line looks like:
> P05 P05.7 09-04-07 7.4.09
> So, I wrote below in my vimfiles.vim,
> let s:line1 = getline(1)
> if s:line1 =~ "^(P[0-9]{2}) \1\.[0-9]"
> setf sierrasym
> endif
> But it does not work. It looks like that =~ operation does not
> support quantifier ({2}) and backreference (\1) I used here. Can you
> help? Thanks.
First off, vim regular expressions (by default, anyway), require you to
use a \ with () and {N}. That, in itself, prevents \1 from working here
- there simply is no match for the literal string '(P[0-9]{2}'.
Secondly, I'd use single quotes to avoid having to quote the
backslashes.
With another tweak for numbers, I'd go for eg. (untested, though)
let s:line1 = getline(1)
if s:line1 =~ '^\(P\d\{2\}\) \1\.\d'
setf sierrasym
endif
Preben
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---