On extending motions and matches

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

On extending motions and matches

Adrien "Pied" Piérard
Hello.

I've registered to this ML a month ago or so, but I think that I
haven't written anything yet.
I've been a (mostly) happy vi/vim user for some 15 years now, so, I'd
like to thank all devs and bug reporters for helping make such great
and essential software.

Now, for the content of the request/remark :
it looks like motions like i" or a' that work with quotations are
hard-coded. As I happen to write a lot of math in latex, I have many $
signs everywhere that I would like to treat as quotations so that I
can do da$ or yi$.
I guess this could be implemented with vimscript, though this does not
explain why the aforementioned motions are hard-coded.
I believe that, at least for single characters bounds, the i/a motions
should be able to work on arbitrary chars, don't you think so?
The idea would be to have
:set sentence_delimiters='"`$^
so that one can do di' ya$ or yi^

For more intricate patterns like
\[ math formula \]
scripts could (should?) be written.

Also, I see no reason to limit the above motions to be restricted to
single lines.

So, do you think that my extension suggestion is acceptable? Or that
current situation is inconsistent and that these hard-coded motions
should be removed and externalised to a script?


Cheers,

P!


PS: I would like to emphasize the fact that latex is a pain to edit
with vim. I'm sure that anyone who has to write latex on a regular
basis will agree. There is definitely room for improvement here.

--
Français, English, 日本語, 한국어

--
You received this message from the "vim_dev" 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 | Threaded
Open this post in threaded view
|

Re: On extending motions and matches

Ingo Karkat
On 22-Jun-2010 04:22, Adrien "Pied" Piérard wrote:

> Hello.
>
> I've registered to this ML a month ago or so, but I think that I
> haven't written anything yet.
> I've been a (mostly) happy vi/vim user for some 15 years now, so, I'd
> like to thank all devs and bug reporters for helping make such great
> and essential software.
>
> Now, for the content of the request/remark :
> it looks like motions like i" or a' that work with quotations are
> hard-coded. As I happen to write a lot of math in latex, I have many $
> signs everywhere that I would like to treat as quotations so that I
> can do da$ or yi$.
> I guess this could be implemented with vimscript, though this does not
> explain why the aforementioned motions are hard-coded.
> I believe that, at least for single characters bounds, the i/a motions
> should be able to work on arbitrary chars, don't you think so?
> The idea would be to have
> :set sentence_delimiters='"`$^
> so that one can do di' ya$ or yi^
>
> For more intricate patterns like
> \[ math formula \]
> scripts could (should?) be written.
>
> Also, I see no reason to limit the above motions to be restricted to
> single lines.
>
> So, do you think that my extension suggestion is acceptable? Or that
> current situation is inconsistent and that these hard-coded motions
> should be removed and externalised to a script?

I think by mentioning the intricate patterns and limitations in your discussion
you've somewhat answered your question yourself: It's good that Vim includes
motions and text objects for very common things (i", at, etc.), and that this is
hard-coded in the C sources for stability and performance reasons. On the other
hand, you've illustrated that even your suggested 'sentence_delimiters' would
only go so far to remove some, but not most of the limitations. Thus, anything
special can and should be implemented in custom Vimscript.

-- regards, ingo
--
  -- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --
  --      http://vim.sourceforge.net/account/profile.php?user_id=9713    --

--
You received this message from the "vim_dev" 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 | Threaded
Open this post in threaded view
|

RE: On extending motions and matches

JohnBeckett
In reply to this post by Adrien "Pied" Piérard
Adrien "Pied" Piérard wrote:
> it looks like motions like i" or a' that work with quotations
> are hard-coded. As I happen to write a lot of math in latex,
> I have many $ signs everywhere that I would like to treat as
> quotations so that I can do da$ or yi$.
> I guess this could be implemented with vimscript, though this
> does not explain why the aforementioned motions are hard-coded.

I don't have an opinion atm on the issue you raise, but in case
it is of interest, we have a relevant "new" tip sitting in the
"to be processed" queue at the wiki:

http://vim.wikia.com/wiki/Text_object_for_formulas_in_Latex

If a Latex person would like to comment on the tip (does
anything need fixing?), please do so on the wiki or here.

John

--
You received this message from the "vim_dev" 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 | Threaded
Open this post in threaded view
|

Re: On extending motions and matches

Ingo Karkat
In reply to this post by Adrien "Pied" Piérard
On 22-Jun-2010 04:22, Adrien "Pied" Piérard wrote:
> As I happen to write a lot of math in latex, I have many $
> signs everywhere that I would like to treat as quotations so that I
> can do da$ or yi$.
> I guess this could be implemented with vimscript, though this does not
> explain why the aforementioned motions are hard-coded.

I've written a set of generic Vimscript functions for defining such mappings,
which I've been using for text objects of email fortunes, diff hunks and Vim
help sections. Prompted by your question, I've polished, documented and
published this as the CountJump plugin. It's not just for text objects, but can
cover motions (e.g. ]$, [$) as well.
    http://www.vim.org/scripts/script.php?script_id=3130

Your "$"-delimited latex text object would be defined via
    call CountJump#TextObject#MakeWithCountSearch('<buffer>', '$', 'ai', 'v',
'\$', '\$')

This snippet could be put into .vim/ftplugin/tex_textobject.vim and you would be
done. I hope this is useful; feedback is welcome.

-- regards, ingo
--
  -- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --
  --      http://vim.sourceforge.net/account/profile.php?user_id=9713    --

--
You received this message from the "vim_dev" 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 | Threaded
Open this post in threaded view
|

Re: On extending motions and matches

Adrien "Pied" Piérard
> I've written a set of generic Vimscript functions for defining such mappings, [...]

Thank you very much, I will try your plugin which may indeed be of
much use to me.

For what it is worth, I am currently using

:vnoremap i$ <C-\><C-n>?\$?b+1<CR>v/\$/b-1<CR>
:vnoremap a$ <C-\><C-n>?\$<CR>v/\$<CR>

which have been collectively written thanks to other users of
#vim@freenode, and work "well enough" (a file with a single ``$'' will
trigger a behaviour different from that of the hardcoded text
objects).

Cheers,

P!
--
Français, English, 日本語, 한국어

--
You received this message from the "vim_dev" 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