[vim/vim] feature: add has('wsl') (PR #10464)

29 views
Skip to first unread message

Kato

unread,
May 21, 2022, 12:34:30 PM5/21/22
to vim/vim, Subscribed

I have added has('wsl') to Vim. This determines if Vim is running on a WSL system.
It is a reproduction of a feature in Neovim and uses the idea of determining if it is running on WSL(see: neovim/neovim#16153), but I have not appropriated any of the source code.

There are a few things to note in the code, which are as follows
・The position of the kernel_release variable declaration is far from where it is actually used.
・The variable "i" is used in another logic.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/10464

Commit Summary

File Changes

(4 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464@github.com>

Kato

unread,
May 21, 2022, 12:45:18 PM5/21/22
to vim/vim, Push

@kat0h pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/push/9946554654@github.com>

LemonBoy

unread,
May 21, 2022, 1:05:34 PM5/21/22
to vim/vim, Subscribed

There's a much simpler detection method that probe one of these two files:

/proc/sys/kernel/osrelease
/proc/version


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/c1133670171@github.com>

ichizok

unread,
May 21, 2022, 3:02:04 PM5/21/22
to vim/vim, Subscribed

・The variable "i" is used in another logic.

How about using vim_strup() and search with uppercase "MICROSOFT"?

And, in f_has(),

#if (defined(UNIX) || defined(VMS)) \

     && (!defined(MACOS_X) || defined(HAVE_CONFIG_H)) \

     && defined(HAVE_SYS_UTSNAME_H)

WSL is on Linux so I think all need is checking only #if defined(__linux__) && defined(HAVE_SYS_UTSNAME_H).


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/c1133752714@github.com>

Gary Johnson

unread,
May 21, 2022, 4:40:39 PM5/21/22
to reply+ACY5DGHLMKLKAZMIMS...@reply.github.com, vim...@googlegroups.com
On 2022-05-21, ichizok wrote:
> And, in f_has(),
>
> #if (defined(UNIX) || defined(VMS)) \
>
> && (!defined(MACOS_X) || defined(HAVE_CONFIG_H)) \
>
> && defined(HAVE_SYS_UTSNAME_H)
>
> WSL is on Linux so I think all need is checking only #if defined(__linux__) &&
> defined(HAVE_SYS_UTSNAME_H).

If Vim doesn't need to know that it's on WSL, whether when being
built or being run, then it shouldn't know. WSL should look like
any other Linux system, so Vim shouldn't care whether it's on WSL or
not. It's up to the user to figure out what flavor of operating
system they're using, if they care. The $OSTYPE environment
variable is good for that.

Regards,
Gary

vim-dev ML

unread,
May 21, 2022, 4:41:02 PM5/21/22
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/c1133765479@github.com>

Kato

unread,
May 21, 2022, 11:07:34 PM5/21/22
to vim/vim, vim-dev ML, Push

@kat0h pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/push/9948372366@github.com>

Kato

unread,
May 21, 2022, 11:23:47 PM5/21/22
to vim/vim, vim-dev ML, Push

@kat0h pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/push/9948410773@github.com>

Kato

unread,
May 22, 2022, 12:05:33 AM5/22/22
to vim/vim, vim-dev ML, Comment

Thank you for checking my PR.

@LemonBoy
Thanks for the suggestion on how to determine WSL. I chose this method because I thought that using uname syscall would be faster to execute and simpler to code than the method of reading the file.

@ichizok
Thanks for the suggestion to use vim_strup(). I was not aware of the existence of vim_strup() and have made the change as I think it is appropriate to use this method in place of the for statement.
Also, thanks for pointing out the appropriate #if condition.

@ Gary (sorry, I don't know how to reply well to vim-ml)
Thanks for pointing that out.
WSL users sometimes use Vim in conjunction with Windows. For example, clipboard integration. At this time, users are aware that Vim is running on WSL.
For this reason, I believe it would be beneficial to users to provide a way to distinguish wsl as well as has('unix'), has('mac'), and has('win64'), even though WSL is Linux.
Also, has('wsl') is implemented in neovim. Of course, Vim and Neovim are different projects, and there is no need to adapt Vim to Neovim's specifications. However, I believe it would be beneficial to be able to identify wsl in a similar API.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/c1133813918@github.com>

Maxim Kim

unread,
May 22, 2022, 3:15:15 AM5/22/22
to vim/vim, vim-dev ML, Comment

I use if exists("$WSLENV") for that.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/c1133834575@github.com>

Gary Johnson

unread,
May 22, 2022, 4:01:01 AM5/22/22
to reply+ACY5DGFH5EVVLMFNVN...@reply.github.com, vim...@googlegroups.com
On 2022-05-21, Kato wrote:

> @ Gary (sorry, I don't know how to reply well to vim-ml)

No problem. I don't know how to reply properly to both the list and
the forum from the list, either, so I reply to both and live with
the duplicate messages in the list.

> Thanks for pointing that out.
> WSL users sometimes use Vim in conjunction with Windows. For example, clipboard
> integration. At this time, users are aware that Vim is running on WSL.
> For this reason, I believe it would be beneficial to users to provide a way to
> distinguish wsl as well as has('unix'), has('mac'), and has('win64'), even
> though WSL is Linux.
> Also, has('wsl') is implemented in neovim. Of course, Vim and Neovim are
> different projects, and there is no need to adapt Vim to Neovim's
> specifications. However, I believe it would be beneficial to be able to
> identify wsl in a similar API.

I agree that it would be beneficial for a user to be able to
identify the current operating environment, but that is not the
purpose of has(). The purpose of has() is to allow the user to
determine whether a feature is supported. There is no feature that
Vim has to support that I know of other than a Unix/POSIX
environment to build or run on WSL.

When has() reports that Vim has 'unix', 'mac' or 'win64', it is
telling the user how Vim was built, not what the current operating
environment is.

You could as well use has() to report whether Vim is running on
Debian or Ubuntu or Red Hat or Fedora or CentOS. That may be good
to know, but those are not features and it is not the purpose of
has() to report their existence.

It was a mistake for neovim to hijack has() for that purpose. Vim
should not repeat that mistake.

If a user needs to determine the flavor of Unix being used, there
are already mechanisms to determine that, such as $OSTYPE, uname and
/proc/version.

Regards,
Gary

vim-dev ML

unread,
May 22, 2022, 4:01:19 AM5/22/22
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/10464/c1133840011@github.com>

Kato

unread,
May 22, 2022, 4:52:06 AM5/22/22
to vim/vim, vim-dev ML, Comment

@ Gary
My understanding of the purpose of has() was lacking. Thank you very much for your kind explanation.
I will close this PR.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/c1133849220@github.com>

Kato

unread,
May 22, 2022, 4:52:07 AM5/22/22
to vim/vim, vim-dev ML, Comment

Closed #10464.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/issue_event/6655860362@github.com>

Bram Moolenaar

unread,
May 22, 2022, 7:52:13 AM5/22/22
to vim/vim, vim-dev ML, Comment

Assuming that if exists("$WSLENV") works, then I don't see a reason for a has() item.
Adding a remark about WSL in the help seems useful. How about this:

When using Vim on WSL (Windows Subsystem for Linux) the remarks here do not
apply, `has('win32')` will return false then.  In case you need to know
whether Vim is running on WSL you can use `exists('$WSLENV')`.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/c1133878885@github.com>

Kato

unread,
May 23, 2022, 6:10:24 AM5/23/22
to vim/vim, vim-dev ML, Comment

I believe it would be beneficial to give users a hint on how to determine WSL.
I have verified that exists('$WSLENV') works as intended in Windows, WSL, Linux and Mac environments.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/c1134476860@github.com>

Christian Brabandt

unread,
May 23, 2022, 8:22:59 AM5/23/22
to vim/vim, vim-dev ML, Comment

It is here:

835ee98#diff-c951a6c3c6aa1b6ef94a0348e454fd20590c3d4dc0503e3bb3755ad28bd16179


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/10464/c1134606781@github.com>

Reply all
Reply to author
Forward
0 new messages