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

47380Re: "gq" with hanging indent?

Expand Messages
  • William Natter
    Feb 2, 2004
    • 0 Attachment
      Gumnos (Tim Chase) wrote:

      >I've been poking around the help (and among vim-tips/scripts), and
      >can't find any obvious solution to this. I'm looking for a simple way
      >to get the "gq" family of reformatting commands to reformat the
      >paragraph with a hanging indent:
      >
      >---+---+------------|
      >foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
      >
      > bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar
      >
      >
      >each line currently gets reformatted (gqq) as
      >
      >---+---+------------|
      >foo foo foo foo foo
      >foo foo foo foo foo
      >foo foo foo foo foo
      >
      > bar bar bar bar
      > bar bar bar bar
      > bar bar bar bar
      > bar bar bar
      >
      >but what I'm looking for is the ability to have each line after the
      >first indented one tab-width like
      >
      >---+---+------------|
      >foo foo foo foo foo
      > foo foo foo foo
      > foo foo foo foo
      > foo foo
      >
      > bar bar bar bar
      > bar bar bar
      > bar bar bar
      > bar bar bar
      > bar bar
      >
      >where the + signs are the tab stops and the | is the textwidth
      >
      >I currently have to do it manually, using a "gq" command to split the
      >whole thing, join the 2nd-n lines back together, indent it, and then
      >resplit the whole remainder again. however, there's room for things
      >to go wrong--rejoining can grab too much if you did a "gqq" and
      >there's no empty line between the current one and the next one.
      >
      >Any grand ideas? (This has the feel of a crusty script laying around
      >on Dr. Chip's hard drive somewhere, or that Benji or someone has
      >hacked at one point) I know there's something smart in vim there, as
      >folks seem to be able to do it with code...perhaps with '='?
      >
      >Thanks,
      >
      >-tim
      >
      >
      >
      >
      >
      >
      >
      >
      >
      No grand idea here, just that adding "2" in your formatoptions global
      variable will indent the remainder of a paragraph with the indent of the
      second line:

      :set fo+=2

      So, if you write:

      foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo
      foo (snip) foo

      you have to first create a line below with the indent you want (a
      "blank" line suffices), and type "gqq". Now delete the line you
      created. In short, "Vim" speak:

      o<space><space><space><space><Esc>kgqqjdd

      or

      o<Tab><Esc>kgqqjdd

      which you can easily map.

      William
    • Show all 10 messages in this topic