检查是否在 Vim 中使用 Windows 控制台,而在 Linux 的 Windows 子系统中?
Check if using Windows console in Vim while in Windows Subsystem for Linux?
我在 Linux 的 Windows 子系统中使用 Vim。 windows 命令提示符有一个错误 renders the background color incorrectly。
修复是 set t_ut=
。我认为只有在 Windows 控制台内使用 Vim 时才应用此修复程序,而不是在所有情况下都应用此修复程序。
不幸的是,我不确定如何检测是否正在使用 Windows 控制台,因为我在 Linux 的 Windows 子系统内。
我使用以下代码实现了 Roadowl 的评论。
let uname = substitute(system('uname'),'\n','','')
if uname == 'Linux'
if system('$PATH')=~ '/mnt/c/WINDOWS'
" We are in Windows Subsystem
endif
endif
更新:我结合了 roadowl 和 bk2204 的回答:
let uname = substitute(system('uname'),'\n','','')
if uname == 'Linux'
let lines = readfile("/proc/version")
if lines[0] =~ "Microsoft"
return 1
endif
endif
通常情况下,人们会通过检测终端类型来解决此类问题,但似乎 Microsoft Terminal 报告 xterm-256color
确实不支持此功能。
可以使用如下函数检测一个是否是 运行 WSL:
function! IsWSL()
if has("unix")
let lines = readfile("/proc/version")
if lines[0] =~ "Microsoft"
return 1
endif
endif
return 0
endfunction
这与微软建议检测WSL的方式一致
我在 Linux 的 Windows 子系统中使用 Vim。 windows 命令提示符有一个错误 renders the background color incorrectly。
修复是 set t_ut=
。我认为只有在 Windows 控制台内使用 Vim 时才应用此修复程序,而不是在所有情况下都应用此修复程序。
不幸的是,我不确定如何检测是否正在使用 Windows 控制台,因为我在 Linux 的 Windows 子系统内。
我使用以下代码实现了 Roadowl 的评论。
let uname = substitute(system('uname'),'\n','','')
if uname == 'Linux'
if system('$PATH')=~ '/mnt/c/WINDOWS'
" We are in Windows Subsystem
endif
endif
更新:我结合了 roadowl 和 bk2204 的回答:
let uname = substitute(system('uname'),'\n','','')
if uname == 'Linux'
let lines = readfile("/proc/version")
if lines[0] =~ "Microsoft"
return 1
endif
endif
通常情况下,人们会通过检测终端类型来解决此类问题,但似乎 Microsoft Terminal 报告 xterm-256color
确实不支持此功能。
可以使用如下函数检测一个是否是 运行 WSL:
function! IsWSL()
if has("unix")
let lines = readfile("/proc/version")
if lines[0] =~ "Microsoft"
return 1
endif
endif
return 0
endfunction
这与微软建议检测WSL的方式一致