记录一下,没准以后换设备能用上。
首先去 Microsoft Store text{Microsoft Store} Microsoft Store 里下载 U b u n t u rm Ubuntu Ubuntu 和 Windows Terminal text{Windows Terminal} Windows Terminal 。没有 Microsoft text{Microsoft} Microsoft 账号的,可以立刻注册,很快而且免费。然后去 启用或关闭 Windows 功能 内选中 Hyper-V 和 适用于 Linux 的 Windows 子系统。
运行 Ubuntu text{Ubuntu} Ubuntu,无论哪个版本。它会自动安装。搞定之后我们就获得了 wsl.exe,可以用 cmd 或 powershell 或 win+R 运行之,都可以进入 “虚拟机” 的终端操作界面。本机会被挂载到路径 /mnt 下,内有 /c、/d 等就是本地磁盘。
记得更换软件源。这是国内 U b u n t u rm Ubuntu Ubuntu 基本操作。比如清华源。然后你可以装 g++ 和 gdb 咯!
用 cmd 呼出 wsl 不太美观,所以才推荐下载 Windows Terminal text{Windows Terminal} Windows Terminal 。不出意外它会自动装填两个配置文件(可用选项卡),图标分别是经典小企鹅,还有下载的 U b u n t u rm Ubuntu Ubuntu 的图标。在设置里查看配置文件,其一的运行方案(即 命令行 子项)是 wsl.exe 另一个是 ubuntu*.exe 。保留前者。将其设为启动时默认配置文件(于左侧 启动 项中)。然后你就可以用鼠标右键菜单中 “在终端中打开”,直接用 “虚拟机” 进入本机文件夹了!或者把 启动目录 设为 /mnt/? 等本地路径,也很方便。
我很喜欢 noi linux 2 text{noi linux 2} noi linux 2 系统配色,所以我要使用配色方案 Tango Dark,去下载字体然后安装(选中所有文件后右键菜单内有 “安装” 选项),将字体调为 Ubuntu Mono 。而且 v i m rm vim vim 默认配色方案需设定为 ron 。对了,Tango Dark 背景颜色不太对,自己改成 #300A24 吧。
然后是光标的问题。用此文中所述方式,可以改变光标的形状(和闪烁)但是没法做到光标亮起时文字自动反色!这就导致方块型光标很影响文本可见性……我去查了 xterm text{xterm} xterm 的控制序列,根本没找到当前字符反色的选项……
而且,上面的光标配置方案是永久的(退出 v i m rm vim vim 后仍起效)所以最好 autocmd 改回来。贴上完整的 vimrc 文件,记得它是在 /etc/vim 或 /usr/share/vim 内(二者完全相同,感觉类似软链接):
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
runtime! debian.vim
" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"au BufReadPost * if line("'"") > 1 && line("'"") <= line("$") | exe "normal! g'"" | endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"filetype plugin indent on
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
" set command for clipboard
vnoremap ;x :!/mnt/c/Windows/System32/clip.exe
vnoremap ;y :!/mnt/c/Windows/System32/clip.exeu
nnoremap ;p :read !/mnt/c/Windows/System32/paste.exe il
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
function MatchCharacter(prev)
if a:prev == '('
return ')'
elseif a:prev == '['
return ']'
elseif a:prev == '{'
return '}'
elseif (a:prev == '"') || (a:prev == "'")
return a:prev
else
return ""
endif
endfunction
inoremap ( ()
inoremap [ []
inoremap { {}
inoremap ' ''
inoremap " ""
inoremap =AutoDelete()
function AutoDelete()
let prev = getline('.')[col('.')-2]
if getline('.')[col('.')-1] == MatchCharacter(prev)
return "2s"
else
return ""
endif
endfunction
set showcmd
set number
set cindent
set autoindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
set noexpandtab
set mouse=a
set foldenable
set foldmethod=manual
set cc=80
colorscheme ron
nnoremap :!clear:w:!g++ % -o %:r.exe -std=c++11 -O2 -Wall -Wconversion -Wshadow
nnoremap :!clear:!time ./%:r.exe
nnoremap :!clear:w:!g++ % -o %:r.exe -std=c++11 -Wall -Wconversion -Wshadow -fsanitize=undefined -g
inoremap =BraceAutoNewline()
function BraceAutoNewline()
if getline('.')[col('.')-2] == '{' && getline('.')[col('.')-1] == '}'
return "O"
else
return ""
endif
endfunction
if &term =~ "xterm"
let cursorCommand = "[1 q" . "]12;rgb:ad00/c000/ad00\"
let &t_SI = cursorCommand
let &t_SR = cursorCommand
let &t_EI = cursorCommand
unlet cursorCommand
endif
autocmd VimLeave * :!echo -ne " 33[1 q 33]12;rgb:ee00/ee00/ec00x7"
如果还有什么奇怪的东西那就是 clip.exe 和 paste.exe 。因为 wsl 没有 g e d i t rm gedit gedit,最好能直接复制到系统剪贴板。可见此文,大体来说就是调用 Windows text{Windows} Windows 自带程序 clip.exe 来实现剪切。不自带 paste.exe,可以下载,也可以就用 Shift+Insert,因为 L i n u x rm Linux Linux 下这也是很好的选择。——不过我的笔记本没有小键盘……



