Loading ...
Sorry, an error occurred while loading the content.
 

Re: Intelligent IMAP

Expand Messages
  • Luc Hermitte
    ... You would have to play with searchpair() (you d need to call it between 2 to 4 times -- check lh-map-tools code). First to detect there is only one
    Message 1 of 8 , Jul 31, 2007
      On 27 juil, 05:11, "Kazuo Teramoto" <kaz....@...> wrote:
      > for (i = 0; i < n; i++) {
      > i++;
      >
      > } <>
      >
      > And now when I type CTRL+J to get out of {} block I like vim to remove
      > the {} (because the block only have one line).

      You would have to play with searchpair() (you'd need to call it
      between 2 to 4 times -- check lh-map-tools code). First to detect
      there is only one instruction in the current block. Second, to be sure
      the current ')' is related to a for/if/while/... Then, you can select
      the current curly-brackets and remove them.


      > The other situation is if I have a one line for block, like
      >
      > for (i=0;i<n;i++)
      > i++;
      >
      > and hit enter on the end of line 'i++;' I like to vim change this to:
      >
      > for (i=0;i<n;i++) {
      > i++;
      >
      > }<>

      This one seems really awkard and not ergonomic at all. How can you be
      sure if you will add a new instruction in the 'if' block, or if you
      will add an instruction after the 'if' block?
      Moreover, detecting such context will be quite time consuming -- and I
      can't garanty it is even possible.

      For those situations, I have mappings to add/remove/change brackets.

      And if a specialized mapping was really needed, I'd write it this way
      (thanks to map-tools):
      " Surround the current line with {}, put the '{' on the previous
      line
      :inoremap <buffer> <c-x>{ <c-\><c-n><up>Jv$<c-\><c-
      n>@=Surround('{\n',
      \ '\n!mark!\n}!mark!', 0, 1, '!jump!', 1, '{')<cr>


      --
      Luc Hermitte
      http://hermitte.free.fr/vim/


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.