Display current column in statusline

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Display current column in statusline

Marco-4
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Display current column in statusline

Reid Thompson
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Display current column in statusline

Marco-4
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Display current column in statusline

Reid Thompson
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

Re: Display current column in statusline

Bee
In reply to this post by Marco-4
> 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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Display current column in statusline

glts
In reply to this post by Marco-4
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Display current column in statusline

Marco-4
In reply to this post by Marco-4
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.