Really simple abbreviation I can't do

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Really simple abbreviation I can't do

arocker

I hesitate to ask this question, since it appears to be so simple, but the
answer ought to be useful to a lot of people.

There are many constructs in most programming languages which involve
paired characters - {} () [] particularly. It would be helpful for the
first character (or the pair) to insert both ends, then skip back between
them and start inserting. (That avoids leaving unbalances around.)

Despite trying all sorts of combinations, I've been unable to achieve an
abbreviation sequence that doesn't insert a space, either before or
between the pair. Is there one?

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Nikolay Aleksandrovich Pavlov
2017-07-13 22:55 GMT+03:00  <[hidden email]>:

>
> I hesitate to ask this question, since it appears to be so simple, but the
> answer ought to be useful to a lot of people.
>
> There are many constructs in most programming languages which involve
> paired characters - {} () [] particularly. It would be helpful for the
> first character (or the pair) to insert both ends, then skip back between
> them and start inserting. (That avoids leaving unbalances around.)
>
> Despite trying all sorts of combinations, I've been unable to achieve an
> abbreviation sequence that doesn't insert a space, either before or
> between the pair. Is there one?

Why do you want exactly abbreviation? Though there is a Eatchar
technique described right above `:h :abbreviate-local` (under `:h
abbreviations`), I normally see this implemented on top of mappings.

Though personally I do not use things like autoclose, instead just
having simple mappings like `,s` inserting `()` with cursor left on
the closing `)` (so typed text will be inserted in the middle).

>
> --
> --
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Tony Mechelynck
In reply to this post by arocker
On Thu, Jul 13, 2017 at 9:55 PM,  <[hidden email]> wrote:

>
> I hesitate to ask this question, since it appears to be so simple, but the
> answer ought to be useful to a lot of people.
>
> There are many constructs in most programming languages which involve
> paired characters - {} () [] particularly. It would be helpful for the
> first character (or the pair) to insert both ends, then skip back between
> them and start inserting. (That avoids leaving unbalances around.)
>
> Despite trying all sorts of combinations, I've been unable to achieve an
> abbreviation sequence that doesn't insert a space, either before or
> between the pair. Is there one?
>

If you want the brackets to close themselves, you can use _mappings_,
not abbreviations, as follows:

        inoremap ( ()<BS>
        inoremap [ []<BS>
        inoremap { {}<BS>
or maybe instead of this last one,
        inoremap { {<CR>}<Up><End><CR><Space><Space>

-- but if you want someday to type an unpaired bracket you will then
of course have to follow up with a <Del> to delete the just inserted
closing bracket.


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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Nikolay Aleksandrovich Pavlov
2017-07-14 0:45 GMT+03:00 Tony Mechelynck <[hidden email]>:

> On Thu, Jul 13, 2017 at 9:55 PM,  <[hidden email]> wrote:
>>
>> I hesitate to ask this question, since it appears to be so simple, but the
>> answer ought to be useful to a lot of people.
>>
>> There are many constructs in most programming languages which involve
>> paired characters - {} () [] particularly. It would be helpful for the
>> first character (or the pair) to insert both ends, then skip back between
>> them and start inserting. (That avoids leaving unbalances around.)
>>
>> Despite trying all sorts of combinations, I've been unable to achieve an
>> abbreviation sequence that doesn't insert a space, either before or
>> between the pair. Is there one?
>>
>
> If you want the brackets to close themselves, you can use _mappings_,
> not abbreviations, as follows:
>
>         inoremap ( ()<BS>
>         inoremap [ []<BS>
>         inoremap { {}<BS>
> or maybe instead of this last one,
>         inoremap { {<CR>}<Up><End><CR><Space><Space>
>
> -- but if you want someday to type an unpaired bracket you will then
> of course have to follow up with a <Del> to delete the just inserted
> closing bracket.

I would rather suggest using `<C-v>{` then `(<Del>`: no need to move
hand to the other block. And, of course, if using my mappings instead
(`,s` for `()`, `,h` for `[]`, `,u` for `<>`, `,f` for `{}`) `<C-v>`
will not be needed. One of the reasons I keep using them is that
typing them is faster as they do not involve higher row (and shift
should you use `us` keymap) and positioning for both keys may be
performed simultaneously as `,` is to be pressed by one finger and
everything else by others.

Also all your mappings are incorrect: first ones use `<BS>`, pretty
much sure you meant `<Left>`. As for the last one: it ignores
&shiftwidth, using two space indent always. Just use

    inoremap {<CR> {<C-o>o}<C-o>O

Most of time indentation will be just fine due to indent scripts,
including additional indentation on the new line created by the last
`<C-o>O`.

>
>
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Nikolay Aleksandrovich Pavlov
2017-07-14 1:03 GMT+03:00 Nikolay Aleksandrovich Pavlov <[hidden email]>:

> 2017-07-14 0:45 GMT+03:00 Tony Mechelynck <[hidden email]>:
>> On Thu, Jul 13, 2017 at 9:55 PM,  <[hidden email]> wrote:
>>>
>>> I hesitate to ask this question, since it appears to be so simple, but the
>>> answer ought to be useful to a lot of people.
>>>
>>> There are many constructs in most programming languages which involve
>>> paired characters - {} () [] particularly. It would be helpful for the
>>> first character (or the pair) to insert both ends, then skip back between
>>> them and start inserting. (That avoids leaving unbalances around.)
>>>
>>> Despite trying all sorts of combinations, I've been unable to achieve an
>>> abbreviation sequence that doesn't insert a space, either before or
>>> between the pair. Is there one?
>>>
>>
>> If you want the brackets to close themselves, you can use _mappings_,
>> not abbreviations, as follows:
>>
>>         inoremap ( ()<BS>
>>         inoremap [ []<BS>
>>         inoremap { {}<BS>
>> or maybe instead of this last one,
>>         inoremap { {<CR>}<Up><End><CR><Space><Space>
>>
>> -- but if you want someday to type an unpaired bracket you will then
>> of course have to follow up with a <Del> to delete the just inserted
>> closing bracket.
>
> I would rather suggest using `<C-v>{` then `(<Del>`: no need to move
> hand to the other block. And, of course, if using my mappings instead
> (`,s` for `()`, `,h` for `[]`, `,u` for `<>`, `,f` for `{}`) `<C-v>`
> will not be needed. One of the reasons I keep using them is that
> typing them is faster as they do not involve higher row (and shift
> should you use `us` keymap) and positioning for both keys may be
> performed simultaneously as `,` is to be pressed by one finger and
> everything else by others.
>
> Also all your mappings are incorrect: first ones use `<BS>`, pretty
> much sure you meant `<Left>`. As for the last one: it ignores
> &shiftwidth, using two space indent always. Just use

Err, if I read correctly what are you suggesting will use &shiftwidth
*plus* two spaces. Last can just be removed to achieve the same result
as my variant (minus possible differences in interaction with undo or
`.`: not sure, but my autoclose mappings tend to have issues with
that).

>
>     inoremap {<CR> {<C-o>o}<C-o>O
>
> Most of time indentation will be just fine due to indent scripts,
> including additional indentation on the new line created by the last
> `<C-o>O`.
>
>>
>>
>> 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 [hidden email].
>> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Ben Fritz
Use mappings as suggested here: http://vim.wikia.com/wiki/Automatically_append_closing_characters

But insert a <C-G>u before moving the cursor, to keep it all part of the same undo sequence, so that undo/redo is not broken.

Someone should really update the tip for that...

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

arocker
> Use mappings as suggested here:
>

Thanks for everyone who has responded. I'm still curious about the extra
space inserted by the :ab, when exactly the same sequence, (as far as I
can see) does not generate it.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Nikolay Aleksandrovich Pavlov
2017-07-14 23:16 GMT+03:00  <[hidden email]>:
>> Use mappings as suggested here:
>>
>
> Thanks for everyone who has responded. I'm still curious about the extra
> space inserted by the :ab, when exactly the same sequence, (as far as I
> can see) does not generate it.

There is no “extra space” inserted, abbreviation is triggered only
after you type some text and a character which triggers the
abbreviation (space in some cases) *and that character is not being
removed*, it just stays there in an input buffer to be processed after
abbreviation is expanded. By default all characters except for control
ones are processed by inserting them into the buffer at the cursor
position, space is not a control character.

Eatchar technique I referenced in the first message works around the
problem for the cases when it is needed.

>
> --
> --
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Really simple abbreviation I can't do

Tony Mechelynck
On Sat, Jul 15, 2017 at 12:49 AM, Nikolay Aleksandrovich Pavlov
<[hidden email]> wrote:

> 2017-07-14 23:16 GMT+03:00  <[hidden email]>:
>>> Use mappings as suggested here:
>>>
>>
>> Thanks for everyone who has responded. I'm still curious about the extra
>> space inserted by the :ab, when exactly the same sequence, (as far as I
>> can see) does not generate it.
>
> There is no “extra space” inserted, abbreviation is triggered only
> after you type some text and a character which triggers the
> abbreviation (space in some cases) *and that character is not being
> removed*, it just stays there in an input buffer to be processed after
> abbreviation is expanded. By default all characters except for control
> ones are processed by inserting them into the buffer at the cursor
> position, space is not a control character.
>
> Eatchar technique I referenced in the first message works around the
> problem for the cases when it is needed.
>

Or, to trigger an abbreviation without typing an additional character,
you can hit Ctrl-] (as explained 32 lines below the help tag reached
by ":help abbreviations".

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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...