> Not exactly (can't define custom collections), Thank you for your response, it was worth the wait. The confirmation that such a feature does not yet exist in Vim is still helpful, as I am now aware that I am not missing out on an existing feature. (Faced with Vim, I always feel in the presence of an iceberg, and that there is much more functionality to the tool than what is visible as the tip.)
> but you can define > custom patterns and then do things like: > > :let pattern_var='[A-Z][A-Z][1-4]' > :let @/='\<'.pattern_var.'\>' > :%s//replacement1/g > :let @/='ABC'.pattern_var'.'XYZ' > :%s//replacement2/g Thank you, I won't be using the above example in this case, but I have put it in my notebook as it contains a wealth of information. > Alternatively, you can use control+R on the command-line to bring > in an expression register: > ... > As yet one more alternative, if you haven't use the > command-window... My application is for batch processing of a file using a vim script which has several substitute statements, one of which is shown below: " CHANGE: lhs = bit_test (var, bit); TO: var & (1 << bit) :sil! %s/bit_test\s*(\s*\([0-9A-Za-z_\[\]]\+\)\s*,\s*\([0-9A-Za-z_\[\]] \+\)\s*)/\1 \& (1 << \2)/g The pattern [0-9A-Za-z_\[\]] matches a construct such as array[ii] which var and bit may be. I make use of this pattern in several substitute statements in addition to the one above, and to cut down on errors I was looking for a way to abstract it out. I cannot use identifier character class \i because it does not match array subscript brackets. I did not want to mess w/ isident as the help file warns against it. > > :s/[A-Z1234]/foo/g > > Just to clarify this pattern, it would turn "AX4" into > "foofoofoo", and turn "AX5" into "foofoo5". What you describe > sounds like you're using "[A-Z][A-Z][1-4]" as your pattern. Thanks, you are right - I tried to come up w/ a contrived example and of course, it was wrong! ;-) Here is some additional information that I came across on this subject since my original post, which may be of help to others: This capability is referenced as "named capturing groups". AFAIK, it does not yet exist as a native feature in any tool. There is something called "Named Groups" in Python and .NET Languages, described in the book Beginning Regular Expressions [2005] by Andrew Watt, p. 187, but that feature SEEMS to store the result of the capture into a named variable, not the pattern itself (although I am not sure, as I haven't played with it). The closest solution I have found (after SEVERAL Google searches over couple of days) is the following: http://tinyurl.com/dysmuj The above example shows how you can build up a dictionary using Vim's matchlist feature, and refer to items through subscripts up to 9. How would I go about submitting a request to Vim development for named capturing groups? Thank you - Todd --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
