HermannHeilner wrote:
> Search a specific pattern A, then search a specific pattern
> B, then mark the letters between these two patterns and copy
> these into a new file.

While a general solution is tricky, if certain restraints apply,
this might work well.

For example, suppose you know in advance that:
- A is aaa and B is ttt
- Matches only occur in a single line (you won't have A on one
  line with B on a following line).
- Your copy will include A and B (remove them later).

Then, you could do this:
    /aaa.\{-}ttt
    :CopyMatches
    :new
    "+p
    :%s/^aaa//
    :%s/ttt$//

The first command is a search for 'aaa' followed by 'ttt' (on
the same line), with any text in between, as little as possible.

The second command uses a script from:
http://vim.wikia.com/wiki/Copy_the_search_results_into_clipboard

The remaining commands create a new buffer, paste the clipboard,
then delete 'aaa' at the beginning of each line, and 'ttt' at
the end of each line. A more clever command would delete both at
the same time (try :%s/aaa\zs.\{-}\zettt/&/g).

Unfortunately, CopyMatches has a bug with patterns including \zs
or \ze otherwise the above could be simplified. The search
    /aaa\zs.\{-}\zettt

finds just the text between 'aaa' and 'ttt', so if CopyMatches
did not have its bug, it would copy just that text and you would
not have to delete the unwanted stuff later.

Another possibility would be to search for the first pattern,
then search for the second, then use a script to copy the wanted
text. You would start with Vim script that used histget() to
retrieve the last two search strings, and the current contents of
the buffer (with all line breaks removed, assuming they are not
wanted). Then the script would do some clever stuff (not rocket
science), possibly calling a Python script if necessary.

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

Reply via email to