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

Mapping Macro using smartindent

Expand Messages
  • Sven Kämpf
    Hello, Itry to speed up writing using mappings. Smartindent is on, but doesn t work appropriatly. Example: Assume the following mapping: imap {
    Message 1 of 6 , Jul 28, 2013
    • 0 Attachment
      Hello,

      I try to speed up writing using mappings.
      Smartindent is on, but doesn't work appropriatly.

      Example:

      Assume the following mapping:

      imap { {}<Esc>i<CR><Esc>ko

      Typing "{" (Quotes for clarification) results in
      "
      {
        _
      }
      " (where "_" is the cursor position) -> Perfect.


      But:


      --->
      line n:  for(int i(0);i<v.size();++i)_
      <---

      ...though typing <Esc>o leads to
      ---->
      line n  : 
      for(int i(0);i<v.size();++i)
      line n+1:  _
      <----

      ..typing '{' (using the mapping from above) leads to
      ---->
      line n  :  for(int i(0);i<v.size();++i)
      line n+1:{
      line n+2:  _
      line n+3:}
      <----

      How can I get this?(Appearing the brackets right below the 'f' in the same column)
      ---->
      line n  :  for(int i(0);i<v.size();++i)
      line n+1:  {
      line n+2:    _
      line n+3:  }
      <----

      Thank you in advance for help.

      Best Sven K.

      --
      --
      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
       
       
    • Ben Fritz
      ... I suggest using cindent instead of smartindent. Or better yet, filetype plugin indent on in your .vimrc. smartindent is not so smart sometimes. -- -- You
      Message 2 of 6 , Jul 28, 2013
      • 0 Attachment
        On Sunday, July 28, 2013 9:09:42 AM UTC-5, Sven Kämpf wrote:
        > Hello,
        >
        >
        >
        > I try to speed up writing using mappings.
        >
        > Smartindent
        > is on, but doesn't
        > work appropriatly.
        >
        >
        >
        > Example:
        >
        >
        >
        > Assume the following mapping:
        >
        >
        >
        > imap {
        > {}<Esc>i<CR><Esc>ko
        >

        I suggest using cindent instead of smartindent. Or better yet, "filetype plugin indent on" in your .vimrc.

        smartindent is not so smart sometimes.

        --
        --
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • SVN77KMF
        ... Thank you for your suggestions, but unfortunately it doesn t work. Another Example: If I type: go {} ...in insert mode, than the following
        Message 3 of 6 , Jul 28, 2013
        • 0 Attachment
          On Monday, July 29, 2013 3:45:56 AM UTC+2, Ben Fritz wrote:
          > On Sunday, July 28, 2013 9:09:42 AM UTC-5, Sven Kämpf wrote:
          >
          > > Hello,
          >
          > >
          >
          > >
          >
          > >
          >
          > > I try to speed up writing using mappings.
          >
          > >
          >
          > > Smartindent
          >
          > > is on, but doesn't
          >
          > > work appropriatly.
          >
          > >
          >
          > >
          >
          > >
          >
          > > Example:
          >
          > >
          >
          > >
          >
          > >
          >
          > > Assume the following mapping:
          >
          > >
          >
          > >
          >
          > >
          >
          > > imap {
          >
          > > {}<Esc>i<CR><Esc>ko
          >
          > >
          >
          >
          >
          > I suggest using cindent instead of smartindent. Or better yet, "filetype plugin indent on" in your .vimrc.
          >
          >
          >
          > smartindent is not so smart sometimes.

          Thank you for your suggestions, but unfortunately it doesn't work.
          Another Example:

          If I type:

          <Space><Space>go<CR>{}

          ...in insert mode, than the following appears:

          ^__go
          ^__{}

          But If I make a mapping like this:

          inoremap <Leader>go go<CR>{}

          ...and type:

          <Space><Space><Leader>go

          ...then the following appears:

          --
          --
          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@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • SVN77KMF
          ... Thank you for your suggestions, but unfortunately it didn t work. Another Example: If I type: go {} ...in insert mode, than the following
          Message 4 of 6 , Jul 28, 2013
          • 0 Attachment
            On Monday, July 29, 2013 3:45:56 AM UTC+2, Ben Fritz wrote:
            > On Sunday, July 28, 2013 9:09:42 AM UTC-5, Sven Kämpf wrote:
            >
            > > Hello,
            >
            > >
            >
            > >
            >
            > >
            >
            > > I try to speed up writing using mappings.
            >
            > >
            >
            > > Smartindent
            >
            > > is on, but doesn't
            >
            > > work appropriatly.
            >
            > >
            >
            > >
            >
            > >
            >
            > > Example:
            >
            > >
            >
            > >
            >
            > >
            >
            > > Assume the following mapping:
            >
            > >
            >
            > >
            >
            > >
            >
            > > imap {
            >
            > > {}<Esc>i<CR><Esc>ko
            >
            > >
            >
            >
            >
            > I suggest using cindent instead of smartindent. Or better yet, "filetype plugin indent on" in your .vimrc.
            >
            >
            >
            > smartindent is not so smart sometimes.

            Thank you for your suggestions, but unfortunately it didn't work.

            Another Example:

            If I type:

            <Space><Space>go<CR>{}

            ...in insert mode, than the following appears:

            ^__go
            ^__{}

            ('^' -> start of line, '_' -> space)

            But If I make a mapping like this:

            inoremap <Leader>go go<CR>{}

            ...and I type:

            <Space><Space><Leader>go

            ...in insert mode, then the following appears:

            ^__go
            ^{}

            It looks like indentation wouldn't work in mappings, right?

            If so, what options do I have to solve this problem?

            THX in advance.

            --
            --
            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@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Ben Fritz
            ... Actually, yes it does. In fact, your mapping works just fine for me, launching gvim with gvim -N -u NONE -i NONE, setting your mapping, setting cindent ,
            Message 5 of 6 , Jul 29, 2013
            • 0 Attachment
              On Monday, July 29, 2013 12:45:09 AM UTC-5, SVN77KMF wrote:
              >
              > It looks like indentation wouldn't work in mappings, right?
              >
              >

              Actually, yes it does. In fact, your mapping works just fine for me, launching gvim with gvim -N -u NONE -i NONE, setting your mapping, setting 'cindent', and typing the following text:

              {

              for (a=1; a<5; a++)
              {

              }
              }

              The {..} below the for loop was indented automatically by Vim.

              >
              > If so, what options do I have to solve this problem?
              >

              Something else in your config is probably interfering, or maybe you want your code formatted differently than Vim's cindent settings will give you. You can try messing with the cinoptions settings.

              --
              --
              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@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • SVN77KMF
              Hello Ben, sry for stealing your time. :/ I m an jackass. Actually the whole thing works - better than me. Because: I tried to do the following while testing:
              Message 6 of 6 , Jul 29, 2013
              • 0 Attachment
                Hello Ben,

                sry for stealing your time. :/
                I'm an jackass.
                Actually the whole thing works - better than me.

                Because:

                I tried to do the following while testing:

                __for(;;)
                __{
                __}

                Cindent/Smarindent catches that there is no need to start at column 2 because there is no embedding block around.

                Instead this:

                {
                __for(;;)
                __{
                __}
                }

                works just fine - as you said.

                Anyhow, thank you very much for support.
                Your last post (the outer brackets espacially ;) ) helped. LOL

                Best, Sven

                --
                --
                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@....
                For more options, visit https://groups.google.com/groups/opt_out.
              Your message has been successfully submitted and would be delivered to recipients shortly.