Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect whitespace in status line #3898

Open
john-cj opened this issue Feb 2, 2019 · 9 comments
Open

Incorrect whitespace in status line #3898

john-cj opened this issue Feb 2, 2019 · 9 comments

Comments

@john-cj
Copy link

john-cj commented Feb 2, 2019

:ver
VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:36:07)
MS-Windows 32-bit GUI version with OLE support
Included patches: 1
Compiled by mool@tororo

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

@tonymec
Copy link

tonymec commented Feb 3, 2019

  1. As your :version heading shows, this Vim executable was compiled 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-cj
Copy link
Author

john-cj commented Feb 3, 2019

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

@chrisbra
Copy link
Member

chrisbra commented Feb 3, 2019

I think this is a duplicate of #1431

@brammool
Copy link
Contributor

brammool commented Feb 3, 2019 via email

@john-cj
Copy link
Author

john-cj commented Feb 3, 2019

@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. Probably someone could post it as code?

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

@andymass
Copy link

andymass commented Feb 3, 2019

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

@andymass
Copy link

andymass commented Feb 3, 2019

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-cj
Copy link
Author

john-cj commented Feb 8, 2019

Does it exist a better workaround then using "?

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

@Acelya-9028
Copy link

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

Shados added a commit to Shados/nix-config-shared that referenced this issue Apr 19, 2021
Shados added a commit to Shados/nix-config-shared that referenced this issue Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants