Tuesday, January 31, 2012

Re: A Versatile fmt command

Christian made many valid points, some still outstanding.

On Jan 31, 11:06 am, Christian Brabandt <cbli...@256bit.org> wrote:

>There are some issues with this script.

Yes the if statements are not written right.. Probably best to create
3 separate if/endif statement to cover all combinations. The
combinations bear thought since,
substitute commands hand off text that can be processed by later
commands.

> I am not sure, what you need the keepmarks command there.

It seems that an external filter like fmt wipes out marks otherwise -
or completely, since it basically deletes a text block and replaces it
with a new one.

> I think you want rather: :keepmarks 'A,'B!fmt -p '>'

Yes that might work, once A and B are set properly.
>
> The /^[^\.] matches lines, that do not start with either a dot or a
> backspace (so you don't need to escape the . in a collation) and I am
> not sure, if you need the search command in front of the :s command.

Correct on this. I did not think of silent! and did not realize there
was an e flag for
sub.

> Then I think you can do something like /^ *$\|\%$kB

I can mark a line as part of a movement command?

> It is mapped to, v which was simply map v !}fmt before. I learned one must
> unmap v first, before a new map will work.
> I am not sure this is true. It should work without unmapping v first,

Did not seem to. However, I work with a winchester mystery house of
configurations. He insists on setting compatible with all the limits
that imposes, has literally thousands of abbreviations and maps. I
thought a `latter' map of
v would also replace an earlier one too. But it did not seem to.

I did think that a script could read the '< and '> marks afterr <esc>,
but my script seemed unaware of them. Again perhaps the complex .vimrc
file. It may work now, that I have installed a non-crippled version of
vim.

Actually, testing for a current mark set after an initial cursor
position has advantages: I think it would be easier to, for instance
filter the whole file through the script by going to line 1, then to
the end and marking A. But I can not think of
a mark to test for that might only get set for this script.

It would also be very nice to use vim's internal gq command. But that
requires setting paragraphs to any line at all that starts with a dot.
Someone there must be a way to do this. Will paragraphs take only
strings or can one fool it with some kind of eval or expand function?
I guess the script could search the text block, retrieve every line
with an initial dot, temporarily set paragraphs accordingly, and then
use gq?

What do I want my script to do: Format a paragraph, treating all
lines that start with a dot as paragraph boundaries, if a mark is
given format a user defined text block instead of one paragraph, if
the paragraph or block contains comment or quote strings like >,
format those lines while retaining the initial quote string for each
line.

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

No comments: