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

Display current column in statusline

Expand Messages
  • Marco
    Hi, how can I display the current column in the status line? Having read :h statusline I found %c which looks promising, but it counts bytes and not
    Message 1 of 9 , Jan 25, 2014
    • 0 Attachment
      Hi,

      how can I display the current column in the status line?

      Having read :h statusline I found %c which looks promising, but it
      counts bytes and not characters. I'd like to have the column
      separated by characters, not bytes. %v works, but only if no tabs
      are being used. Here an example:

      123 56789
      “äå µåäö”

      I'd like to display the number indicated in the first column. The
      following works for the first to third column until the tabs come
      into play.

      :set statusline=%v

      The following works only for the first line, but not the second one.

      :set statusline=%c

      VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 9 2013 04:13:14)
      Included patches: 1-52

      Marco

      --
      --
      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.
    • Reid Thompson
      ... set statusline=%t%m%r%h%w %{&ff} %Y dec/hex %03.3b/ %02.2B line %l col %c%V of %L lines %p%% yields .vimrc unix VIM dec/hex 115/73 line 50 col
      Message 2 of 9 , Jan 25, 2014
      • 0 Attachment
        On 1/25/2014 7:25 PM, Marco wrote:
        > Hi,
        >
        > how can I display the current column in the status line?
        >
        > Having read :h statusline I found %c which looks promising, but it
        > counts bytes and not characters. I'd like to have the column
        > separated by characters, not bytes. %v works, but only if no tabs
        > are being used. Here an example:
        >
        > 123 56789
        > “äå µåäö”
        >
        > I'd like to display the number indicated in the first column. The
        > following works for the first to third column until the tabs come
        > into play.
        >
        > :set statusline=%v
        >
        > The following works only for the first line, but not the second one.
        >
        > :set statusline=%c
        >
        > VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 9 2013 04:13:14)
        > Included patches: 1-52
        >
        > Marco
        >
        set statusline=%t%m%r%h%w\ %{&ff}\ %Y\ dec/hex\ \%03.3b/\%02.2B\ line\
        %l\ col\ %c%V\ of\ %L\ lines\ %p%%
        yields
        .vimrc unix VIM dec/hex 115/73 line 50 col 1 of 634 lines 7%

        --
        --
        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.
      • Marco
        ... This statusline uses %c which operates on bytes instead of characters. In my example it displays “5” if the cursor is placed on the digit “5”,
        Message 3 of 9 , Jan 25, 2014
        • 0 Attachment
          On 2014–01–25 Reid Thompson wrote:

          > set statusline=%t%m%r%h%w\ %{&ff}\ %Y\ dec/hex\ \%03.3b/\%02.2B\
          > line\ %l\ col\ %c%V\ of\ %L\ lines\ %p%%
          > yields
          > .vimrc unix VIM dec/hex 115/73 line 50 col 1 of 634 lines 7%

          This statusline uses %c which operates on bytes instead of
          characters. In my example it displays “5” if the cursor is placed on
          the digit “5”, which is correct. But if you move the cursor down one
          line (the column stays the same, it's still five) it displays column
          “9” which is not what I want. The displayed column should be “5” if
          positioned on the “µ”.

          Marco

          --
          --
          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.
        • Reid Thompson
          ... for me it display both byte and char when I put the cursor on this char v “äå µåäö” ^ it shows col 9-5, 9 bytes, 5 chars [No Name][+] unix
          Message 4 of 9 , Jan 25, 2014
          • 0 Attachment
            On 1/25/2014 8:45 PM, Marco wrote:
            > On 2014–01–25 Reid Thompson wrote:
            >
            >> set statusline=%t%m%r%h%w\ %{&ff}\ %Y\ dec/hex\ \%03.3b/\%02.2B\
            >> line\ %l\ col\ %c%V\ of\ %L\ lines\ %p%%
            >> yields
            >> .vimrc unix VIM dec/hex 115/73 line 50 col 1 of 634 lines 7%
            > This statusline uses %c which operates on bytes instead of
            > characters. In my example it displays “5” if the cursor is placed on
            > the digit “5”, which is correct. But if you move the cursor down one
            > line (the column stays the same, it's still five) it displays column
            > “9” which is not what I want. The displayed column should be “5” if
            > positioned on the “µ”.
            >
            > Marco
            >
            for me it display both byte and char
            when I put the cursor on this char v
            “äå µåäö”
            ^
            it shows col 9-5, 9 bytes, 5 chars
            [No Name][+] unix dec/hex 181/B5 line 2 col 9-5 of 3 lines 66%

            If I put it on the last char in the line, the double quotes, it shows
            [No Name][+] unix dec/hex 8>3/0>4 line 2 col 17-9 of 3 lines 66%

            17 bytes, 9 chars

            --
            --
            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.
          • Bee
            ... In your example it looks like you used a tab char and set ts=8 to move the 5 over. If set ts=8 then the 5 IS at column 9, as it would be if you
            Message 5 of 9 , Jan 25, 2014
            • 0 Attachment
              > This statusline uses %c which operates on bytes instead of
              > characters. In my example it displays “5” if the cursor is placed
              > on the digit “5”, which is correct. But if you move the cursor
              > down one line (the column stays the same, it's still five) it
              > displays column “9” which is not what I want. The displayed
              > column should be “5” if positioned on the “µ”.

              In your example it looks like you used a tab char and 'set ts=8'
              to move the '5' over. If 'set ts=8' then the '5' IS at column 9,
              as it would be if you used spaces.

              With vim 7.4.160 using %v all columns with '5' whether using a
              tab char or expanded to spaces shows column 9.

              " using %v, tab char the '5' and 'µ' are at column 9
              123 56789
              “äå µåäö”

              " using %v, spaces the '5' and 'µ' are at column 9
              123 56789
              “äå µåäö”

              Bill

              --
              --
              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.
            • Marco
              ... In your quote the tab is missing which was present in my OP. It is unclear if your output corresponds to the version with tabs or space. Without tab I get
              Message 6 of 9 , Jan 26, 2014
              • 0 Attachment
                On 2014–01–25 Reid Thompson wrote:

                > On 1/25/2014 8:45 PM, Marco wrote:
                > >This statusline uses %c which operates on bytes instead of
                > >characters. In my example it displays “5” if the cursor is placed on
                > >the digit “5”, which is correct. But if you move the cursor down one
                > >line (the column stays the same, it's still five) it displays column
                > >“9” which is not what I want. The displayed column should be “5” if
                > >positioned on the “µ”.
                > >
                > >Marco
                > >
                > for me it display both byte and char
                > when I put the cursor on this char v
                > “äå µåäö”
                > ^

                In your quote the tab is missing which was present in my OP. It is
                unclear if your output corresponds to the version with tabs or
                space. Without tab I get the same result.

                Marco

                --
                --
                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.
              • Marco
                ... I want to count a tab only once, since it is one character. This is what the %c flag almost does. %c displays “5-9”, five bytes, column nine if tabs
                Message 7 of 9 , Jan 26, 2014
                • 0 Attachment
                  On 2014–01–25 Bee wrote:

                  > > This statusline uses %c which operates on bytes instead of
                  > > characters. In my example it displays “5” if the cursor is placed
                  > > on the digit “5”, which is correct. But if you move the cursor
                  > > down one line (the column stays the same, it's still five) it
                  > > displays column “9” which is not what I want. The displayed
                  > > column should be “5” if positioned on the “µ”.
                  >
                  > In your example it looks like you used a tab char and 'set ts=8'
                  > to move the '5' over. If 'set ts=8' then the '5' IS at column 9,
                  > as it would be if you used spaces.

                  I want to count a tab only once, since it is one character. This is
                  what the %c flag almost does. %c displays “5-9”, five bytes, column
                  nine if tabs are being expanded.

                  I'd like to have a simple character count without dealing with tab
                  expansion, so the “µ” would be character five.

                  Marco

                  --
                  --
                  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.
                • glts
                  Marco, ... For me one of the nicest feature of the status line is the %{} item that lets you evaluate any expression and insert the result. ... This counts
                  Message 8 of 9 , Jan 26, 2014
                  • 0 Attachment
                    Marco,

                    On Sunday, January 26, 2014 1:25:24 AM UTC+1, Marco wrote:
                    > how can I display the current column in the status line?
                    >
                    > Having read :h statusline I found %c which looks promising, but it
                    > counts bytes and not characters. I'd like to have the column
                    > separated by characters, not bytes. %v works, but only if no tabs
                    > are being used. Here an example:
                    >
                    > 123 56789
                    > “äå µåäö”
                    >
                    > I'd like to display the number indicated in the first column. The
                    > following works for the first to third column until the tabs come
                    > into play.
                    >
                    > :set statusline=%v
                    >
                    > The following works only for the first line, but not the second one.
                    >
                    > :set statusline=%c

                    For me one of the nicest feature of the status line is the %{} item that
                    lets you evaluate any expression and insert the result.

                    Here is my solution (goes on a single line):

                    :set statusline+=%{strlen(substitute(getline('.')[:col('.')-1],'.','.','g'))}

                    This counts 'a', 'ä', <Tab> all as one column. It does so by grabbing
                    the current line, substituting a period for every character to the left
                    of the cursor, and returning the length of the resulting string.

                    Best,


                    --
                    David

                    --
                    --
                    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.
                  • Marco
                    ... It grabs the line, trims it to the cursor column, replaces all characters with a 1-byte character, and counts the length of the string: Marco ¹
                    Message 9 of 9 , Jan 26, 2014
                    • 0 Attachment
                      On 2014–01–26 Marco wrote:

                      > how can I display the current column in the status line?
                      >
                      > Having read :h statusline I found %c which looks promising, but it
                      > counts bytes and not characters. I'd like to have the column
                      > separated by characters, not bytes.

                      Here's a solution (thanks to benjifisher¹):

                      :let &statusline = "%{strlen(substitute(strpart(getline('.'), 0, col('.')), '.', 'x', 'g'))}"

                      It grabs the line, trims it to the cursor column, replaces all
                      characters with a 1-byte character, and counts the length of the
                      string:

                      Marco

                      ¹ http://stackoverflow.com/a/21367789/1013470

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