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

Patch: better auto-format w/ 2nd line indent (fo+=a2)

Expand Messages
  • Tor Perkins
    Greetings all, Using auto-format with 2nd line indent (fo+=a2) works well, but there is a situation where it s a little awkward... Lets say we want to make a
    Message 1 of 1 , Apr 26, 2013
    • 0 Attachment
      Greetings all,

      Using auto-format with 2nd line indent (fo+=a2) works well, but there
      is a situation where it's a little awkward...

      Lets say we want to make a new paragraph with auto-format and 2nd line
      indent that will end up looking something like this:

      xx aaaa aaaa aaaa
      bbbb bbbb bbbb
      cccc cccc cccc

      To get started, lets also turn on smartindent:

      vi:textwidth=25:formatoptions=a2:smartindent

      xx aaaa aaaa aaaa
      bbbb

      Above, we see that as we enter the text, since there is not yet a 2nd
      line, smartindent wraps the text to the same indent as the 1st line
      (no problem).

      The problem occurs if you attempt to adjust the 2nd line indent by
      inserting a space at column 1 on the 2nd line (i.e. you stay in insert
      mode and just hit <Home><Space>). The text becomes:

      xx aaaa aaaa aaaa
      bbbb

      ... Which is OK. What's not OK is that the cursor is positioned on
      the 1st line on the 3rd char from the end. This is surprising and it
      makes it awkward to insert more space chars at the beginning of the 2nd
      line as the cursor jumps up to the 1st line with each new space char.

      This problem does not happen if the text is in a comment. If we turn
      on all of the cool comment handling features, like so:

      :set formatoptions+=cjoqr

      After repeating the above (but with a preceding comment char), we see
      this result:

      # xx aaaa aaaa aaaa
      # bbbb

      ... But this time the cursor stays on the 2nd line and jumps from
      column 1 to column 6 (the 1st 'b', which is OK). Subsequent inserted
      space chars offer no surprise cursor jumps (the cursor stays on the
      1st 'b' as one would expect).

      Please find the attached diff that makes the non-comment behavior
      match the comment behavior. The diff also includes a new test case.

      The patch tries to mimic what was happening when comments are turned
      on and it survives a 'make test' as of v.7.3.905.

      Thank you for your time and consideration!

      - Tor


      --
      --
      You received this message from the "vim_dev" 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_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+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.