Friday, September 8, 2017

Re: how to redefine paragraphs?

On Sat, Sep 9, 2017 at 12:18 AM, Jose Caballero
<jcaballero.hep@gmail.com> wrote:
> I have searched on google using the same words as the subject, but
> didn't get too much information. Or didn't understand what I found.
> Maybe people in this list can provide for hints on how to google it
> more precisely.
>
>
> So this is what I would like to be able to do.
> When editing python code, I would like to be able to define a new type
> of paragraph (and this applies only to functions and methods) as:
>
> -- beginning:
> the line starting with "def" or " def"
>
> -- end:
> the blank line before next "def" or " def"
> or
> the blank line before next line with content in column 0 (for example,
> next class)
> or
> end of buffer if none of the above are possible.
>
> It would be nice if that works for copying/deleting "paragraphs" -in
> order words, for the ip commands-, but also for movements to first and
> last line.
> Is something like that even possible?
> If yes, I only need the correct keywords to investigate it myself.
>
>
> A second question would be if it is possible w/o messing with current
> definition of paragraph.
> Just wondering if what I am looking for can be done but things like
> ip, or movement like }, keep working as they are.
> Maybe with operator-pending mappings to redefine the new boundaries?
>
>
> Thanks a lot in advance, whether it is possible or not.
> Cheers,
> Jose

The details are at ":help paragraph" but I don't understand it much
myself. IIUC (and that's a big if) the only _possible_ paragraph
boundaries are as follows:

• an empty line (with not even a space in it) is always a paragraph end
• a { in column 1 is a paragraph start if 'cpoptions' includes the {
flag (which by default only happens in 'compatible' mode with
$VIM_POSIX unset; but you can set it separately if you want)
• if the 'paragraphs' option is not empty, then a dot in column 1
immediately followed by one of the disjoint character pairs making up
'paragraphs' is a paragraph start. By default, this means one of .IP
.LP .PP .QP .P<space> .TP .HP .LI .Pp .Lp .It .pp .lp .ip .bp
• A section boundary is also a paragraph boundary. Section boundaries
are as follows:
· A form feed (Ctrl-L) character in column 1 is always a section start
· If 'sections' is not empty, then a dot in column 1 followed by a
character pair in 'sections' is a section start. By default this means
one of .SH .NH .H<space> .HU .nh .sh

Nothing else can be a paragraph boundary. In particular, "def" cannot
define a paragraph start regardless of any spaces before it on the
same line, an empty line is always a paragraph end, a line with one or
more whitespace characters is never a paragraph boundary, and in
addition, though it is not explicitly specified in the help AFAICT,
the first line in the file is always the start of a section and the
last line in the file is always the end of a section (and therefore,
in both cases, of a paragraph). I'm not sure what happens in the limit
case of a zero-length file. Maybe it is made up of one empty section
containing one empty paragraph containing one empty sentence; or maybe
it has no sections, no paragraphs and no sentences whatsoever.

If someone understands Vim paragraphs better than I do, please chime
in and say whether I interpreted that help item correctly or not.


Best regards,
Tony.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment