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

using formatoptions +a autoflow

Expand Messages
  • Eric Smith
    I like to use autoflow but wish to have it automatically switch off when editing structured paragraphs. For example when editing emails, I do not want autoflow
    Message 1 of 4 , Jul 18, 2013
    • 0 Attachment
      I like to use autoflow but wish to have it automatically switch
      off when editing structured paragraphs.

      For example when editing emails, I do not want autoflow to
      reformat the headers or the signature.

      How could I have it switch off when editing these paragraphs
      and on again with other text?

      --
      Eric Smith

      --
      --
      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.
    • Paul Isambert
      ... You could try something like this, which is quite hackish, though: function s:checkformat () let ln = line( . ) let signature = 0 while ln 1 if
      Message 2 of 4 , Jul 18, 2013
      • 0 Attachment
        Eric Smith <es@...> a écrit:
        > I like to use autoflow but wish to have it automatically switch
        > off when editing structured paragraphs.
        >
        > For example when editing emails, I do not want autoflow to
        > reformat the headers or the signature.
        >
        > How could I have it switch off when editing these paragraphs
        > and on again with other text?

        You could try something like this, which is quite hackish, though:

        function s:checkformat ()
        let ln = line('.')
        let signature = 0
        while ln > 1
        if getline(ln) == '--'
        let signature = 1
        break
        end
        let ln -= 1
        endwhile
        if signature
        set formatoptions-=a
        else
        set formatoptions+=a
        end
        echo &formatoptions
        endfunction

        augroup checkformat
        au!
        " Perhaps you'll want that more specific, e.g. *.eml
        au InsertEnter * call s:checkformat()
        augroup END

        This checks whether one of the lines above the current one is “--”,
        and if so removes the “a” in “formatoptions”, because it means you’re
        in the email signature. The checking occurs whenever you go from
        normal to insert mode, so it won’t work when you move from the email’s
        body to the signature without leaving and reentering insert mode. To
        be sure you miss as few occasions as possible, you could add the
        function to the “CursorMovedI” autocommand or even “InsertCharPre”,
        but I don’t know how much it would affect performance. Technically you
        could check the kind of paragraph you’re in each time the cursor is
        moved.

        I’ll let you find the rest of the function for header fields :)

        Best,
        Paul

        --
        --
        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 think I d approach this in one of two ways: 1. Define normal text as a text, and structured text as a comment (if possible). Then you can use the c
        Message 3 of 4 , Jul 19, 2013
        • 0 Attachment
          On Thursday, July 18, 2013 3:41:35 PM UTC-5, Eric Smith wrote:
          > I like to use autoflow but wish to have it automatically switch
          >
          > off when editing structured paragraphs.
          >
          >
          >
          > For example when editing emails, I do not want autoflow to
          >
          > reformat the headers or the signature.
          >
          >
          >
          > How could I have it switch off when editing these paragraphs
          >
          > and on again with other text?
          >

          I think I'd approach this in one of two ways:

          1. Define normal text as a text, and "structured" text as a comment (if possible). Then you can use the 'c' and 't' flags in formatoptions to control where it applies.
          2. Create my own formatexpr function that checks on the region it's in before making any changes.

          --
          --
          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.
        • Eric Smith
          Cool Ben I will give this a go. It will hopefully reduce my expletive count when editing emails :) -- Eric Smith Ben Fritz wrote on Fri-19-Jul 13 2:04PM ...
          Message 4 of 4 , Jul 22, 2013
          • 0 Attachment
            Cool Ben

            I will give this a go. It will hopefully reduce my expletive
            count when editing emails :)

            --
            Eric Smith

            Ben Fritz wrote on Fri-19-Jul 13 2:04PM
            > On Thursday, July 18, 2013 3:41:35 PM UTC-5, Eric Smith wrote:
            > > I like to use autoflow but wish to have it automatically switch
            > >
            > > off when editing structured paragraphs.
            > >
            > >
            > >
            > > For example when editing emails, I do not want autoflow to
            > >
            > > reformat the headers or the signature.
            > >
            > >
            > >
            > > How could I have it switch off when editing these paragraphs
            > >
            > > and on again with other text?
            > >
            >
            > I think I'd approach this in one of two ways:
            >
            > 1. Define normal text as a text, and "structured" text as a comment (if possible). Then you can use the 'c' and 't' flags in formatoptions to control where it applies.
            > 2. Create my own formatexpr function that checks on the region it's in before making any changes.
            >
            > --
            > --
            > 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.
            >

            --
            --
            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.