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

Different center alignment

Expand Messages
  • Pablo Giménez
    Hi vims. when writing dov files is very common to use this format: 2.1 User Manual *user-manual* In this example the begining of the line is in the first
    Message 1 of 8 , Jun 2, 2010
      Hi vims.
      when writing dov files is very common to use this format:

      2.1 User Manual                                                                    *user-manual*

      In this example the begining of the line is in the first column and the end of it it at the latest column, usually 80 cos the textwidth by defualt is this.
      In between I use spaces to fill the line.
      I have tried with the :center command and other options from several plugins, all of them do the same with center alignment, they truncate the speaces in between to give you something like:
                               2.1 User Manual      *user-manual*
      So basically I just need something that expand all the spaces to fill the whole line, somethign that expands rather than truncate.
      Any ideas?
      thanks

      --
      Un saludo
      Best Regards
      Pablo Giménez

      --
      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
    • Jürgen Krämer
      Hi, ... (this is on line). I assumed the line always ends with a tag between two stars, so the first part ^ s* (. {- } ) s + ( *.* * ) s*$ matches the left
      Message 2 of 8 , Jun 2, 2010
        Hi,

        Pablo Giménez wrote:
        >
        > when writing dov files is very common to use this format:
        >
        > 2.1 User
        > Manual *user-manual*
        >
        > In this example the begining of the line is in the first column and the
        > end of it it at the latest column, usually 80 cos the textwidth by
        > defualt is this.
        > In between I use spaces to fill the line.
        > I have tried with the :center command and other options from several
        > plugins, all of them do the same with center alignment, they truncate
        > the speaces in between to give you something like:
        > 2.1 User Manual *user-manual*
        > So basically I just need something that expand all the spaces to fill
        > the whole line, somethign that expands rather than truncate.
        > Any ideas?

        :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=submatch(1) . repeat(' ', &tw ? &tw : &wm ? winwidth(0) - &wm : winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)/

        (this is on line). I assumed the line always ends with a tag between two
        stars, so the first part

        ^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$

        matches the left text with "\(.\{-\}\)", some whitespace with "\s\+" and
        the tag with "\(\*.*\*\)". Leading and trailing whitespace are ignored
        and the text and the tag are captured.

        The replacement text

        \=submatch(1) . repeat(' ', &tw ? &tw : &wm ? winwidth(0) - &wm : winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)

        concatenates three parts. The first and third part are straightforward:
        these are the captured submatches. The second part is a bit more complex.
        We want to insert some spaces so we use the repeat() function. The first
        parameter says what to repeat and the second one how often. The count
        is calculated by first determining the maximum length of the whole line
        with

        &tw ? &tw : &wm ? winwidth(0) - &wm : winwidth(0)

        This says: If 'textwidth' is set, use it; else if 'wrapmargin' is set,
        subtract its value from the width of the current window; else use the
        whole window width.

        From this width the lengths of both submatches are subtracted, resulting
        in the number of spaces to insert between the text and the tag.

        Regards,
        Jürgen

        --
        Sometimes I think the surest sign that intelligent life exists elsewhere
        in the universe is that none of it has tried to contact us. (Calvin)

        --
        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
      • Christian Brabandt
        ... Shouldn t that be something like that =submatch(1) . repeat( , (&tw ? &tw : &wm ? winwidth(0) - &wm : winwidth(0)) - len(submatch(1)) -
        Message 3 of 8 , Jun 2, 2010
          On Wed, June 2, 2010 1:30 pm, Jürgen Krämer wrote:
          > The replacement text
          >
          > \=submatch(1) . repeat(' ', &tw ? &tw : &wm ? winwidth(0) - &wm :
          > winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)
          >

          Shouldn't that be something like that
          \=submatch(1) . repeat(' ', (&tw ? &tw : &wm ? winwidth(0) - &wm :
          winwidth(0)) - len(submatch(1)) - len(submatch(2))) . submatch(2)

          (note that added paranthesis...)

          Also, one should be aware, that len and strlen returns the byte length
          of its argument, but one rather would like to have the character width.
          That would mean, one needs to do
          len(substitute(submatch(1), '.', 'x', 'g')) to return the character width.

          regards,
          Christian

          --
          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
        • Jürgen Krämer
          Hi, ... yes, you are right. I had first tested this with a temporary variable that held the result of &tw ? &tw : &wm ? winwidth(0) - &wm : winwidth(0) and
          Message 4 of 8 , Jun 2, 2010
            Hi,

            Christian Brabandt wrote:
            > On Wed, June 2, 2010 1:30 pm, Jürgen Krämer wrote:
            >> The replacement text
            >>
            >> \=submatch(1) . repeat(' ', &tw ? &tw : &wm ? winwidth(0) - &wm :
            >> winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)
            >>
            >
            > Shouldn't that be something like that
            > \=submatch(1) . repeat(' ', (&tw ? &tw : &wm ? winwidth(0) - &wm :
            > winwidth(0)) - len(submatch(1)) - len(submatch(2))) . submatch(2)
            >
            > (note that added paranthesis...)

            yes, you are right. I had first tested this with a temporary variable
            that held the result of "&tw ? &tw : &wm ? winwidth(0) - &wm : winwidth(0)"
            and did not test again after inserting this into the replacement expression.

            Thanks,
            Jürgen

            --
            Sometimes I think the surest sign that intelligent life exists elsewhere
            in the universe is that none of it has tried to contact us. (Calvin)

            --
            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
          • David Fishburn
            ... I wrapped that into a command: command! FullJustifyHelpLine ... &tw : &wm ? winwidth(0) - &wm : winwidth(0)) - len(submatch(1)) - len(submatch(2))) .
            Message 5 of 8 , Jun 2, 2010
              On 02/06/2010 8:54 AM, Christian Brabandt wrote:
              > On Wed, June 2, 2010 1:30 pm, Jürgen Krämer wrote:
              >
              >> The replacement text
              >>
              >> \=submatch(1) . repeat(' ',&tw ?&tw :&wm ? winwidth(0) -&wm :
              >> winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)
              >>
              >>
              > Shouldn't that be something like that
              > \=submatch(1) . repeat(' ', (&tw ?&tw :&wm ? winwidth(0) -&wm :
              > winwidth(0)) - len(submatch(1)) - len(submatch(2))) . submatch(2)
              >
              > (note that added paranthesis...)
              >
              > Also, one should be aware, that len and strlen returns the byte length
              > of its argument, but one rather would like to have the character width.
              > That would mean, one needs to do
              > len(substitute(submatch(1), '.', 'x', 'g')) to return the character width.
              >
              I wrapped that into a command:
              command! FullJustifyHelpLine
              :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=submatch(1) . repeat(' ', (&tw ?
              &tw : &wm ? winwidth(0) - &wm : winwidth(0)) - len(submatch(1)) -
              len(submatch(2))) . submatch(2)/<CR>


              So, with your cursor on that line, simply run:
              :FullJustifyHelpLine

              Can anyone think of a better name :-)

              Dave

              --
              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
            • Christian Brabandt
              ... I have a different suggestion, if I may ;) ... ((&tw?&tw:&wm?winwidth(0)-&wm:winwidth(0)) - len(split(submatch(1).submatch(2), zs ))), , submatch(2))/
              Message 6 of 8 , Jun 2, 2010
                On Wed, June 2, 2010 3:46 pm, David Fishburn wrote:
                > On 02/06/2010 8:54 AM, Christian Brabandt wrote:
                >> On Wed, June 2, 2010 1:30 pm, Jürgen Krämer wrote:
                >>
                >>> The replacement text
                >>>
                >>> \=submatch(1) . repeat(' ',&tw ?&tw :&wm ? winwidth(0) -&wm :
                >>> winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)
                >>>
                >>>
                >> Shouldn't that be something like that
                >> \=submatch(1) . repeat(' ', (&tw ?&tw :&wm ? winwidth(0) -&wm :
                >> winwidth(0)) - len(submatch(1)) - len(submatch(2))) . submatch(2)
                >>
                >> (note that added paranthesis...)
                >>
                >> Also, one should be aware, that len and strlen returns the byte length
                >> of its argument, but one rather would like to have the character width.
                >> That would mean, one needs to do
                >> len(substitute(submatch(1), '.', 'x', 'g')) to return the character
                >> width.
                >>
                > I wrapped that into a command:
                > command! FullJustifyHelpLine
                > :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=submatch(1) . repeat(' ', (&tw ?
                > &tw : &wm ? winwidth(0) - &wm : winwidth(0)) - len(submatch(1)) -
                > len(submatch(2))) . submatch(2)/<CR>
                >

                I have a different suggestion, if I may ;)
                :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=printf("%s%*.s%s", submatch(1),
                ((&tw?&tw:&wm?winwidth(0)-&wm:winwidth(0)) -
                len(split(submatch(1).submatch(2),'\zs'))), ' ', submatch(2))/

                This should be a little bit shorter and should work with multibyte glyphs
                as well.

                > So, with your cursor on that line, simply run:
                > :FullJustifyHelpLine
                >
                > Can anyone think of a better name :-)

                JustifyHelpHeader

                regards,
                Christian

                --
                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
              • Pablo Giménez
                Thanks guys works like a charms. I am using Christian s version. I prefer the second name: JustifyHelpHeader 2010/6/2 Christian Brabandt
                Message 7 of 8 , Jun 2, 2010
                  Thanks guys works like a charms. I am using Christian's version.
                  I prefer the second name:
                  JustifyHelpHeader

                  2010/6/2 Christian Brabandt <cblists@...>
                  On Wed, June 2, 2010 3:46 pm, David Fishburn wrote:
                  > On 02/06/2010 8:54 AM, Christian Brabandt wrote:
                  >> On Wed, June 2, 2010 1:30 pm, Jürgen Krämer wrote:
                  >>
                  >>> The replacement text
                  >>>
                  >>>    \=submatch(1) . repeat(' ',&tw ?&tw :&wm ? winwidth(0) -&wm :
                  >>> winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)
                  >>>
                  >>>
                  >> Shouldn't that be something like that
                  >> \=submatch(1) . repeat(' ', (&tw ?&tw :&wm ? winwidth(0) -&wm :
                  >> winwidth(0)) - len(submatch(1)) - len(submatch(2))) . submatch(2)
                  >>
                  >> (note that added paranthesis...)
                  >>
                  >> Also, one should be aware, that len and strlen returns the byte length
                  >> of its argument, but one rather would like to have the character width.
                  >> That would mean, one needs to do
                  >> len(substitute(submatch(1), '.', 'x', 'g')) to return the character
                  >> width.
                  >>
                  > I wrapped that into a command:
                  > command! FullJustifyHelpLine
                  > :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=submatch(1) . repeat(' ', (&tw ?
                  > &tw : &wm ? winwidth(0) - &wm : winwidth(0)) - len(submatch(1)) -
                  > len(submatch(2))) . submatch(2)/<CR>
                  >

                  I have a different suggestion, if I may ;)
                  :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=printf("%s%*.s%s", submatch(1),
                  ((&tw?&tw:&wm?winwidth(0)-&wm:winwidth(0)) -
                  len(split(submatch(1).submatch(2),'\zs'))), ' ', submatch(2))/

                  This should be a little bit shorter and should work with multibyte glyphs
                  as well.

                  > So, with your cursor on that line, simply run:
                  > :FullJustifyHelpLine
                  >
                  > Can anyone think of a better name :-)

                  JustifyHelpHeader

                  regards,
                  Christian

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



                  --
                  Un saludo
                  Best Regards
                  Pablo Giménez

                  --
                  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
                • Pablo Giménez
                  ... *tags* : command! JustifyHelpHeader :silent! s/^ s* (. {- } ) s + ([*|].*[*|] ) s*$/ =printf( %s%*.s%s ,
                  Message 8 of 8 , Jun 8, 2010
                    El 2 de junio de 2010 16:48, Pablo Giménez <pablogipi@...> escribió:
                    Thanks guys works like a charms. I am using Christian's version.
                    I prefer the second name:
                    JustifyHelpHeader

                    2010/6/2 Christian Brabandt <cblists@...>

                    On Wed, June 2, 2010 3:46 pm, David Fishburn wrote:
                    > On 02/06/2010 8:54 AM, Christian Brabandt wrote:
                    >> On Wed, June 2, 2010 1:30 pm, Jürgen Krämer wrote:
                    >>
                    >>> The replacement text
                    >>>
                    >>>    \=submatch(1) . repeat(' ',&tw ?&tw :&wm ? winwidth(0) -&wm :
                    >>> winwidth(0) - len(submatch(1)) - len(submatch(2))) . submatch(2)
                    >>>
                    >>>
                    >> Shouldn't that be something like that
                    >> \=submatch(1) . repeat(' ', (&tw ?&tw :&wm ? winwidth(0) -&wm :
                    >> winwidth(0)) - len(submatch(1)) - len(submatch(2))) . submatch(2)
                    >>
                    >> (note that added paranthesis...)
                    >>
                    >> Also, one should be aware, that len and strlen returns the byte length
                    >> of its argument, but one rather would like to have the character width.
                    >> That would mean, one needs to do
                    >> len(substitute(submatch(1), '.', 'x', 'g')) to return the character
                    >> width.
                    >>
                    > I wrapped that into a command:
                    > command! FullJustifyHelpLine
                    > :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=submatch(1) . repeat(' ', (&tw ?
                    > &tw : &wm ? winwidth(0) - &wm : winwidth(0)) - len(submatch(1)) -
                    > len(submatch(2))) . submatch(2)/<CR>
                    >

                    I have a different suggestion, if I may ;)
                    :s/^\s*\(.\{-\}\)\s\+\(\*.*\*\)\s*$/\=printf("%s%*.s%s", submatch(1),
                    ((&tw?&tw:&wm?winwidth(0)-&wm:winwidth(0)) -
                    len(split(submatch(1).submatch(2),'\zs'))), ' ', submatch(2))/
                    I have made a variation of this command to support |tags| and not only *tags* :
                    command! JustifyHelpHeader :silent! s/^\s*\(.\{-\}\)\s\+\([*|].*[*|]\)\s*$/\=printf("%s%*.s%s", submatch(1),((&tw?&tw:&wm?winwidth(0)-&wm:winwidth(0)) - len(split(submatch(1).submatch(2),'\zs'))), ' ', submatch(2))/


                    This should be a little bit shorter and should work with multibyte glyphs
                    as well.

                    > So, with your cursor on that line, simply run:
                    > :FullJustifyHelpLine
                    >
                    > Can anyone think of a better name :-)

                    JustifyHelpHeader

                    regards,
                    Christian

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



                    --
                    Un saludo
                    Best Regards
                    Pablo Giménez



                    --
                    Un saludo
                    Best Regards
                    Pablo Giménez

                    --
                    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
                  Your message has been successfully submitted and would be delivered to recipients shortly.