Thursday, July 13, 2017

Re: Really simple abbreviation I can't do

2017-07-14 0:45 GMT+03:00 Tony Mechelynck <antoine.mechelynck@gmail.com>:
> On Thu, Jul 13, 2017 at 9:55 PM, <arocker@vex.net> 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 vim_use+unsubscribe@googlegroups.com.
> 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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment