[vim/vim] Incorrect whitespace in status line (#3898)

30 views
Skip to first unread message

John

unread,
Feb 2, 2019, 6:16:19 PM2/2/19
to vim/vim, Subscribed

It seems that statusline doesn't properly work with whitespace.

Here is my .vimrc:

set encoding=utf-8
set guifont=Consolas:h10
colorscheme desert

let separator = '    '
set laststatus=2
set statusline=
set statusline+=%n
set statusline+=%{separator}
set statusline+=%t
set statusline+=%=
set statusline+=%(%l:%c%V%)
set statusline+=%{separator}
set statusline+=%{&expandtab?'spaces':'tab\ size'}:\ %{shiftwidth()}
set statusline+=%{separator}
set statusline+=%{&fileformat}
set statusline+=%{separator}
set statusline+=%{(strlen(&fileencoding)?&fileencoding:&encoding).((exists('+bomb')&&&bomb)?'-with-bom':'')}
set statusline+=%{separator}
set statusline+=%{strlen(&filetype)?&filetype:'text'}

And here is how Vim looks:

statusline_bug

As you can see, at some places there are only 3 spaces instead of 4. and looks like a bug for me.

Then, if we use hard-coded spaces instead of separator - everything will be correct:

set encoding=utf-8
set guifont=Consolas:h10
colorscheme desert

set laststatus=2
set statusline=
set statusline+=%n\ \ \ \ "
set statusline+=%t
set statusline+=%=
set statusline+=%(%l:%c%V%)\ \ \ \ "
set statusline+=%{&expandtab?'spaces':'tab\ size'}:\ %{shiftwidth()}\ \ \ \ "
set statusline+=%{&fileformat}\ \ \ \ "
set statusline+=%{(strlen(&fileencoding)?&fileencoding:&encoding).((exists('+bomb')&&&bomb)?'-with-bom':'')}\ \ \ \ "
set statusline+=%{strlen(&filetype)?&filetype:'text'}

statusline_correct


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Tony Mechelynck

unread,
Feb 2, 2019, 7:17:48 PM2/2/19
to vim/vim, Subscribed
  1. As your :version heading shows, this Vim executable was compilmed on the very first day of the 8.1 release, almost 9 months ago. The latest source as of this writing is 8.1.868. Have you tried using a more up-to-date version of Vim?
  2. Since hard-coded spaces work for you, well, use that then.

Best regards,
Tony.

John

unread,
Feb 2, 2019, 8:05:33 PM2/2/19
to vim/vim, Subscribed

As your :version heading shows, this Vim executable was compiled on the very first day of the 8.1 release, almost 9 months ago.

Actually, it some kind of fresh version :-) I downloaded it January 30. It seems that Windows binary is a bit outdated.

Best regards you too :-)

Christian Brabandt

unread,
Feb 3, 2019, 4:39:36 AM2/3/19
to vim/vim, Subscribed

I think this is a duplicate of #1431

Bram Moolenaar

unread,
Feb 3, 2019, 8:53:52 AM2/3/19
to vim/vim, Subscribed

> It seems that statusline doesn't properly work with whitespace.
>
> Here is my .vimrc:
>
> ```vim

> set encoding=utf-8
> set guifont=Consolas:h10
> colorscheme desert
>
> let separator = ' '
> set laststatus=2
> set statusline=
> set statusline+=%n
> set statusline+=%{separator}
> set statusline+=%t
> set statusline+=%=
> set statusline+=%(%l:%c%V%)
> set statusline+=%{separator}
> set statusline+=%{&expandtab?'spaces':'tab\ size'}:\ %{shiftwidth()}
> set statusline+=%{separator}
> set statusline+=%{&fileformat}
> set statusline+=%{separator}
> set statusline+=%{(strlen(&fileencoding)?&fileencoding:&encoding).((exists('+bomb')&&&bomb)?'-with-bom':'')}
> set statusline+=%{separator}
> set statusline+=%{strlen(&filetype)?&filetype:'text'}
> ```
>
> And here is how Vim looks:
>
> ![statusline_bug](https://user-images.githubusercontent.com/18004961/52170281-a1ff9e00-2758-11e9-8772-6f14cd15aef5.png)

>
> As you can see, at some places there are only 3 spaces instead of 4. and looks like a bug for me.
>
> Then, if we use hard-coded spaces instead of `separator` - everything will be correct:
>
> ```vim

> set encoding=utf-8
> set guifont=Consolas:h10
> colorscheme desert
>
> set laststatus=2
> set statusline=
> set statusline+=%n\ \ \ \ "
> set statusline+=%t
> set statusline+=%=
> set statusline+=%(%l:%c%V%)\ \ \ \ "
> set statusline+=%{&expandtab?'spaces':'tab\ size'}:\ %{shiftwidth()}\ \ \ \ "
> set statusline+=%{&fileformat}\ \ \ \ "
> set statusline+=%{(strlen(&fileencoding)?&fileencoding:&encoding).((exists('+bomb')&&&bomb)?'-with-bom':'')}\ \ \ \ "
> set statusline+=%{strlen(&filetype)?&filetype:'text'}
> ```

I hesitate to change how 'statusline' deals with whitespace especially
for %{} items. There are some tricks to drop whitespace, especially if
one of the items is empty. Existing implementations depend on that.

A better solution would be to explicitly have an item that specifies the
amount of white space, which then would be inserted literally.

--
ARTHUR: Charge!
[They all charge with swords drawn towards the RABBIT. A tremendous twenty
second fight with Peckinpahish shots and borrowing heavily also on the
Kung Fu and karate-type films ensues, in which some four KNIGHTS are
comprehensively killed.]
ARTHUR: Run away! Run away!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John

unread,
Feb 3, 2019, 12:00:05 PM2/3/19
to vim/vim, Subscribed

@brammool

I hesitate to change how 'statusline' deals with whitespace especially
for %{} items. There are some tricks to drop whitespace, especially if
one of the items is empty. Existing implementations depend on that.

In other words, it's some kind of bug, which is considered as feature?

bug_feature - copy

A better solution would be to explicitly have an item that specifies
the amount of white space, which then would be inserted literally.

Interesting. As n00b, I don't know the way how it should be done, but
still interesting.

// There are at least 2 Monty Python fans here!

Andy Massimino

unread,
Feb 3, 2019, 2:05:49 PM2/3/19
to vim/vim, Subscribed

What if we allow %0{...} to disable the space eating? Zero pad is not otherwise used for { in the statusline. Implementation is very simple:

--- a/src/buffer.c
+++ b/src/buffer.c
@@ -4223,7 +4223,7 @@ build_stl_str_hl(
            break;

        case STL_VIM_EXPR: /* '{' */
-           itemisflag = TRUE;
+           itemisflag = zeropad ? FALSE : TRUE;
            t = p;
            while (*s != '}' && *s != NUL && p + 1 < out + outlen)
                *p++ = *s++;

Andy Massimino

unread,
Feb 3, 2019, 3:06:29 PM2/3/19
to vim/vim, Subscribed

Although, the other behavior of %{} which one might want to disable is %{000} becomes 0 since it looks like a number. Perhaps some other symbol should be used e.g., %+{".."} which means interpret as a string without the special processing, i.e., not a flag and no conversion to number.

John

unread,
Feb 8, 2019, 4:59:44 PM2/8/19
to vim/vim, Subscribed

Does it exist a better workaround then using "?

" This line is used as separator:
set statusline+=%\ \ \ \ "

Acelya

unread,
Jan 12, 2021, 6:10:06 PM1/12/21
to vim/vim, Subscribed

I have the same problem, is there any news? Thanks


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
1:47 PM (9 hours ago) 1:47 PM
to vim/vim, Subscribed

Closed #3898 as completed via e8d7a40.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/3898/issue_event/25935325985@github.com>

Reply all
Reply to author
Forward
0 new messages