Redefining paragraph text object?

瀏覽次數:30 次
跳到第一則未讀訊息

Silas Silva

未讀,
2012年9月21日 下午5:20:162012/9/21
收件者:vim...@googlegroups.com
Hello all.

I was working around a function to map } and { around it. It is useful
for file formats that have other definitions of paragraph other than ^$.
For DocBook, for instance, it is better to use "<para>" and "</para>".

So I thought: it works for navigation, but not for all other operations
regarding paragraph text object. Would it be possible to change
paragraph text object for my own needs?

There is the 'paragraphs' option, but it look too simple, not accepting
regexp. I couldn't extend it far from the basic nroff setting.

Is it possible?

Thank you.

--
Silas Silva

Gary Johnson

未讀,
2012年9月21日 下午5:48:012012/9/21
收件者:vim...@googlegroups.com
No.

Regards,
Gary

Christian Brabandt

未讀,
2012年9月22日 清晨7:39:262012/9/22
收件者:vim...@googlegroups.com
Hi Gary!
Not built in, but you can of course map { } to something different.
There are several text-object motion scripts at vim.org, this one here
seems to specifically take care of paragraph motion:
http://www.vim.org/scripts/script.php?script_id=3952

Disclaimer: I don't know the plugin and can't say how well it will work
in your case.

regards,
Christian
--
Menschen, die immer daran denken, was andere von ihnen halten, w�ren
sehr �berrascht, wenn sie w��ten, wie wenig die anderen �ber sie
nachdenken.
-- Bertrand A. W. Russell

Gary Johnson

未讀,
2012年9月22日 下午1:04:362012/9/22
收件者:vim...@googlegroups.com
On 2012-09-22, Christian Brabandt wrote:
> Hi Gary!
>
> On Fr, 21 Sep 2012, Gary Johnson wrote:
>
> > On 2012-09-21, Silas Silva wrote:
> > > Hello all.
> > >
> > > I was working around a function to map } and { around it. It is useful
> > > for file formats that have other definitions of paragraph other than ^$.
> > > For DocBook, for instance, it is better to use "<para>" and "</para>".
> > >
> > > So I thought: it works for navigation, but not for all other operations
> > > regarding paragraph text object. Would it be possible to change
> > > paragraph text object for my own needs?
> > >
> > > There is the 'paragraphs' option, but it look too simple, not accepting
> > > regexp. I couldn't extend it far from the basic nroff setting.
> > >
> > > Is it possible?
> >
> > No.
>
> Not built in, but you can of course map { } to something different.
> There are several text-object motion scripts at vim.org, this one here
> seems to specifically take care of paragraph motion:
> http://www.vim.org/scripts/script.php?script_id=3952
>
> Disclaimer: I don't know the plugin and can't say how well it will work
> in your case.

Mappings will work to change the behavior of { and }, but by "other
operations regarding paragraph text object," I assumed the OP was
referring to commands using ap and ip. There is no way that I know
of to change the behavior of commands using those.

I think that's what's addressed by this todo item:

- Add regex for 'paragraphs' and 'sections': 'parare' and 'sectre'.
Combine the two into a regex for searching. (Ned Konz)

Regards,
Gary

Tim Chase

未讀,
2012年9月22日 下午1:32:182012/9/22
收件者:vim...@googlegroups.com
On 09/22/12 12:04, Gary Johnson wrote:
> I think that's what's addressed by this todo item:
>
> - Add regex for 'paragraphs' and 'sections': 'parare' and 'sectre'.
> Combine the two into a regex for searching. (Ned Konz)

I knew I'd seen something like this on the horizon. I'm just
surprised that it hadn't already landed�it's one of those sore spots
I've grumbled about since the 5.x days of Vim.

-tim




Silas Silva

未讀,
2012年9月23日 清晨7:12:142012/9/23
收件者:vim...@googlegroups.com
On Sat, Sep 22, 2012 at 12:32:18PM -0500, Tim Chase wrote:
> On 09/22/12 12:04, Gary Johnson wrote:
> > I think that's what's addressed by this todo item:
> >
> > - Add regex for 'paragraphs' and 'sections': 'parare' and 'sectre'.
> > Combine the two into a regex for searching. (Ned Konz)
>
> I knew I'd seen something like this on the horizon. I'm just
> surprised that it hadn't already landed—it's one of those sore spots
> I've grumbled about since the 5.x days of Vim.

I see there is a todo entry. Working on that. It doesn't look hard
(just add more options and one more case for startPS() in search.c). I
will submit patch later. Thank you.

--
Silas Silva

Marcin Szamotulski

未讀,
2012年9月23日 清晨7:45:002012/9/23
收件者:vim...@googlegroups.com
Then one can define visual maps and operator maps. In one of my plugins
I have:

vmap ip <Plug>SelectCurrentParagraph
omap ip :normal vip<CR> " omap, not onoremap

Similarly for ap. The <Plug>SelectCurrentParagraph is just a map which
selects a paragraph (I think I din't have to write this ;)

Best regards,
Marcin Szamotulski

Christian Brabandt

未讀,
2012年9月23日 清晨7:49:372012/9/23
收件者:vim...@googlegroups.com
Hi Gary!
Yes, but you could omap those text-objects as well. The wiki has
something on that:
http://vim.wikia.com/wiki/Creating_new_text_objects

> I think that's what's addressed by this todo item:
>
> - Add regex for 'paragraphs' and 'sections': 'parare' and 'sectre'.
> Combine the two into a regex for searching. (Ned Konz)

That would be nice as well. I already thought about a patch, but never
really got around in implementing that (and it probably takes a very
long time, until Bram includes it. Look into the todo-list, how many
patches are lying around.)

Mit freundlichen Gr��en
Christian
回覆所有人
回覆作者
轉寄
0 則新訊息