Andy Wokula wrote: > > This does what you want (very useful!): > > http://vim.wikia.com/wiki/Copy_search_matches > > Somehow all of these solutions are less than ideal. > > The best solution according to correct pattern matching > involves :substitute, but it modifies the buffer. You work > around this problem by creating a temporary buffer ... > > I'd favor a solution with > :%s/{pattern}/\=CollectMatch(submatch(0))/gn > > but '\=' and the "n" flag don't work together. > What about a todo item? Add another flag? > > It's quite disappointing that just getting the matched > strings (in a way that is not a workaround) is so hard.
I totally agree with that! I lost quite a bit of hair while fixing the tip. :s///n does not even attempt to do the substitute, which I guess is good from a performance and side effect point of view. However, it is very frustrating that listing search hits is so hard when Vim has all the code to do the job easily and reliably. I have not looked at the relevant source, but it's possible that some moderately minor change would implement a new flag so something like :%s/xxx/yyy/gN would not change the buffer, but would do all the normal work, such as evaluating a \= expression in the replacement. I was wondering whether a change to substitute() might be useful, but I suspect that only :%s/// works in an expected manner with multiline hits and/or patterns involving ^ or $. John -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
