On 19/04/11 03:04, howard Schwartz wrote:
Leslie wrote:

I don't know what to make of this. For one thing I can't type it
without "trailing characters" errors. Is it all one line? Is it an ex
command? I tried inserting the ^M's with ctrl-q-ctrl-m but it
immediately terminated the command.

It is 2 lines, and the ^M is indeed a ctrl-M, that can be typed as you
did, or
by ctrl-q<ENTER>. Depending on your vim options you may also be able to use
<CR> or \n to get the same effect. Let me explain: Lets say you have
sections
each of which begins with a line that has the word, Topic: . Since email
digests have an initial portion that is not marked as a Section, my
first ex
command, inserts a line with the word, Topic: as the first line of the
file. This is the command:

1s/^.*$/Topic: ^M&/

In words, ``Substitute for any line on line 1 of the file, a line with the
word, Topic:, followed by the original line 1''. So line 1 becomes line 2
and a line with, Topic:, is now line one. You probably do not need this
command, if every one of your sections begins with some line you can
identify.

I would have used

        0put ='Topic: '

using the expression register to add a new line before line 1. Well, I suppose that in Vim there are often several ways to do the same thing and that none of them is better or worse than any other, as long as they do the job.


Now, in words, mark lines that start with a line containing, Topic:, and
end one line prior to the next line that contains, Topic: . For the last
block of text, start the block at a line that contains, Topic:, and end
the block with the last line of the file. Do a fold for each block of
text, so marked. The second ex command that does all of this is:

g/^Topic: */,/^Topic: *\|\%$/-1fold

Or instead of adding "Topic" before line 1, you could use /\%^\|^Topic:/ (analogous to what you already do at the end of each block) to match either a Topic: heading or the start of the file. Note that / */ will match *zero* or more spaces, as many as possible. To require at least one space, use \+ instead of *


If you put these two commands in a script, they will be executed, when you
source the script, so you need not prepend a colon or hit return for each
command. Again, you may be interested only in the second command.

Clear I hope?



Best regards,
Tony.
--
Only through hard work and perseverance can one truly suffer.

--
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