Sunday, January 26, 2014

Re: Display current column in statusline

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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: