vim配置记录
前言
仅仅为了记录我究竟怎样改动了vim的配置, 方便还原或者维护更新.
windows 10 vim
终端环境
先按照在 Windows 10 上安装 WSL 一文中给出的方式手动安装wsl2功能组件:
-
确认系统版本在win10 1903以上
-
以管理员身份打开 PowerShell 并运行:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart -
启用虚拟机功能, 以管理员身份打开 PowerShell 并运行:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart -
下载 Linux 内核更新包
-
将 WSL 2 设置为默认版本
wsl --set-default-version 2 -
在windows 应用商店下载ubuntu 2020.04 LST
-
在windows 应用商店下载windows terminal (可选, 但是确实方便很多)
更多关于终端环境的问题可以参考在 Windows 10 上安装 WSL 一文
终端设置
一. 打开ubuntu 20.04 LTS , 完成初始化设置, 设置好用户名(例如: usr )和密码.
二. 启动windows terminal, 打开设置 : 按ctrl + , 或者在 下拉菜单中选择setting.
-
setting页面打开Open JSON file,
{ "disabledProfileSources": [ "Windows.Terminal.Azure" ], } -
找到nerd frons下载并安装[1]喜欢的nerd字体, 例如FiraCode Nerd Font Mono [2] , 并在json文件中对应位置新增
{ "disabledProfileSources": //这个放在最外层括号内 [ "Windows.Terminal.Azure" ], "profiles": { "defaults": {}, "list": [ { "name": "Ubuntu-20.04", //找到这list中的这个项目 "padding": "8", "source": "Windows.Terminal.Wsl", //下面的都是新增内容 "startingDirectory": "//wsl$/Ubuntu-20.04/home/usr" //usr指在 一. 中设置的用户名 "fontFace": "FiraCode Nerd Font Mono", // 根据你下载的不同nerd fonts的名字这里也要变 "fontSize": 15, "fontWeight": "normal", //新增内容完 }, }如果这里用json配置难以理解, 也可以在Windows Terminal 中 setting -> 左边profile ubuntu选项卡 -> 上方Appearance -> 下面的fonts face , 钩上 Show all fonts 并选择nerd fonts 字体
-
修改windows terminal按键, 通过上文提到的json文件中添加代码
{ "actions": [ { "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+shift+c" }, { "command": "find", "keys": "ctrl+shift+f" }, { "command": "paste", "keys": "ctrl+shift+v" }, { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" } ], }将copy 映射为ctrl+shift+c, paste 映射为ctrl+shift+v 腾出ctrl + c 给ubuntu以及vim使用
-
切换终端主题
windows terminal → settings → Color scheme 选择 Tango Dark
三. 通过Windows terminal 打开ubuntu, 设置ubuntu更新源
-
备份source.list
cd /etc/apt/ sudo cp sources.list sources.list.bak && sudo vim sources.list -
编辑source.list
sudo vim sources.list复制以下内容并在Windows terminal中右键, Windows terminal将自行输入它们
#添加阿里源 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse然后按
Esc输入:wq
保存退出
-
更新源
sudo apt update sudo apt upgrade -
修改pip源
mkdir ~/.pip && vim ~/.pip/pip.conf然后在vim中输入
[global] trusted-host=mirrors.aliyun.com index-url=http://mirrors.aliyun.com/pypi/simple/并
:wq保存 -
为vim安装插件管理器plug
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim -
安装pip和python3 dev以及autoformat
静态检查工具yapf太懒了, 换用blacksudo apt install python3-pip sudo apt install cmake build-essential python3-dev #pip install yapf pip install black pip install pylint #静态检查工具 sudo vim .bashrc将下面一句写入.bashrc中
export PATH=/home/blime/.local/bin/:$PATH
-
安装node.js , 注意node.js 版本必须在12以上才能支持后面的补全插件coc.nvim, 而ubuntu自带源apt下载的nodejs版本可能跟不上要求所以这里通过检查https://nodejs.org/dist/ 来寻找适合的版本安装node.js
wget https://nodejs.org/dist/latest-v14.x/node-v14.17.3-linux-x64.tar.gz mkdir .nodejs cp ~/node-v14.17.3-linux-x64.tar.gz ~/.nodejs/node-v14.17.3-linux-x64.tar.gz cd .nodejs tar zxvf node-v14.17.3-linux-x64.tar.gz cd node-v14.17.3-linux-x64/ ./configure make install保险起见,
cd ~ sudo vim .bashrc输入G来到最后
export PATH=/home/用户名/.nodejs/node-v14.17.3-linux-x64/bin:$PATH
然后保存退出
node -v
```
> v14.17.3
看到版本号就算成功了
-
安装clangd支持
来到 LLVM Debian/Ubuntu packages 查看最新的Ubuntu稳定版(stable branch)
系统是Ubuntu 20.04LST 于是添加更新源时找到
Precise, Quantal, Raring, Saucy, Utopic, Artful, Cosmic, Eoan and Trusty are no longer supported by Ubuntu. Repo remains available
Bionic LTS (18.04) - Last update : Tue, 27 Jul 2021 01:58:33 UTC / Revision: 20210726063833+31e75512174e
# i386 not available deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main # 11 deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main # 12 deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 mainFocal (20.04) LTS - Last update : Mon, 26 Jul 2021 21:02:38 UTC / Revision: 20210726052617+3ca6dea05dec
# i386 not available deb http://apt.llvm.org/focal/ llvm-toolchain-focal main deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal main # 11 deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main # 12 deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main这里, 发现最新的稳定版是12, 于是添加源
sudo vim /etc/apt/sources.list按G来到最后, 加入
deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main保存并退出
在bash中输入命令并核对指纹
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -# Fingerprint: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421
然后输入
sudo apt-get update sudo apt-get upgrade sudo apt-get install libc++-12-dev libc++abi-12-dev sudo apt-get install clang-tidy-12 sudo apt-get install clang-12 clang-tools-12 clang-12-doc libclang-common-12-dev libclang-12-dev libclang1-12 clang-format-12 clangd-12 cd /usr/bin sudo ln -s clang-12 clang sudo ln -s clang++-12 clang++ sudo ln -s /usr/bin/llvm-ar-12 /usr/bin/llvm-ar sudo ln -s /usr/bin/llvm-as-12 /usr/bin/llvm-as sudo ln -s /usr/bin/clangd-12 /usr/bin/clangd sudo ln -s /usr/bin/clang-format-12 /usr/bin/clang-format sudo ln -s /usr/bin/clang-tidy-12 /usr/bin/clang-tidy sudo ln -s /usr/bin/scan-build-12 /usr/bin/scan-build这其中包括了编译器, linter, formatter, 还有自动补全联想
-
安装bash lsp
npm i -g bash-language-server这下bash也支持lsp了
这些命令在apt安装失败时可能会用到:
sudo dpkg --remove --force-remove-reinstreq 软件名
sudo apt-get remove 软件名
sudo apt-get autoremove && sudo apt-get autoclean
至此系统部分的配置就算完成了.
vim配置
LSP
参考了vim plus 和 theniceboy的vim配置, 去掉了vim不支持的设置, 并且加了一些注解
添加了来自韦易笑大佬的脚本
snippet的快捷键还不是很成熟
加入了 一些简单的快捷键, 并不保证没有冲突
加入了esc响应时间100ms , 太低了是不好的设置[3]
事实上, 上一节的配置也许看起来很多, 但是关于vim的map是必须记在心里才行, 那些快捷键不去用它, 那么它就是不存在的
真理都只是暗室里的装饰, 只有眼前亮起来了以后才有机会彰显它的价值
vim还有这些亟待解决
- [ ] 无冲突的map key
verbose imap <tab>
coc.nvim的支持情况
| C | python | others | |
|---|---|---|---|
| 自动补全 | \(\surd\) clangd->coc.lsp | coc-pyright | |
| snippet | \(\surd\) snippet | \(\surd\) snippet | |
| 语法检查 | \(\surd\) clangd->coc.lsp | coc-pyright/ pylint in json | |
| 自动format | \(\surd\) clang-format | yapf/neoformat+autopep8 | |
| 自动编译运行 | |||
| debug |
优化
启动时间
调试vim慢的原因方法:
vim –startuptime message.txt
启动后,查看message.txt中,哪个脚本最慢,再考虑能否禁用加载。
接下来,可以正常使用vim,然后输入命令
:scriptnames
查看启动的脚本
cursorline和cursorcolumn
这两个命令用于优化在非插入模式下重绘屏幕的速度
autocmd InsertLeave * call ToggleCursor()
autocmd InsertEnter * call ToggleCursor()
function ToggleCursor() abort
set cursorline!
set cursorcolumn!
endfunction
remote-plugin
找到python的路径:
$ whereis python
> python: /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config /usr/bin/python /usr/bin/python2.7 ...
$ which python
> /usr/bin/python
所以在vimrc中加入
let g:python_host_skip_check=1
let g:python_host_prog = ‘/usr/bin/python‘
let g:python3_host_skip_check=1
let g:python3_host_prog = ‘/usr/bin/python3‘
注意python2 从2020年起已经不维护了
杂项
-
对于前端, 目前不支持x的wsl2事实上并不适合做前端开发, 所以这个vim并没有任何对x的优化也没有前端插件
pylint 可以用coc-setting.json , 大概是pyright
补全打算试试kite.
-
根据日常使用情况来看, 有时候c的formatter不会启动, 很是奇怪
-
打开vim的true color支持
colorscheme srcery if has("termguicolors") " enable true color set termguicolors endif后, onedark 主题变得很丑, 换用其它主题了.
git
同步
为了保证git和系统内的vimrc同步
然后将~/.vimrc内容改成
running time vimrc
以后在新机器上配置vimrc:
$ cd
$ git clone git@github.com:Ik4ruga/vim.git .vim
$ echo "runtime vimrc" > .vimrc
我在修改vim的时候只要保持github上vimrc是最新的就OK[4]
git setting
Checking for existing SSH keys
> ls -all ~/.shh
如果有ssh账户那么它们会打印出来
按照默认设置, 这些公匙的文件名都是像这样:
- id_rsa.pub
- id_ecdsa.pub
- id_ed25519.pub
如果你有存在的ssh key那么就进入add your SSH key to the ssh-agent
否则进入 generate a new SSH key
generate a new SSH key
如果有硬件生成ssh key的设备, 令硬件密钥链接电脑之后进行ssh key授权, 详情见OpenSSH 8.2 release notes.
输入下面的命令生成密钥
$ ssh-keygen -t ed25519 -C "your_email@example.com"
不支持 Ed25519 算法的系统
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
然后选择ssh key密钥文件的保存路径, enter的话会保存在默认路径中
也可以为这个密钥文件添加口令得到更好的保护效果:
$ ssh-keygen -p -f ~/.ssh/id_ed25519
> Enter old passphrase: [Type old passphrase]
> Key has comment ‘your_email@example.com‘
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [Repeat the new passphrase]
> Your identification has been saved with the new passphrase.
生成完后会给出这个key的 random image
关于random image
为什么会有 randomart image?
相比超长字符串,人们更容易接受图形。让我们对比两幅图片的差异比对比两个超长字符串也要容易的多。这就是为什么现在大家使用二维码,而不是复制粘贴 URL 的原因。
Randomart image 通过将 Key 转换成有规律的图片,让人可以更加容易的、快速的对比 Key 的异同。
如何生成?
看了上面的故事,来说一说 randomart image 具体是如何生成的。我们知道 OpenSSH Key 的指纹是一个 MD5 校验和,同事可以用 16 进制表示出来,类似这样:
fc:94:b0:c1:e5:b0:98:7c:58:43:99:76:97:ee:9f:b7
当然,也可以用二进制来表示。于是按照 Peter 的走路方式,我们定义如下走位:
“00” 表示向西北(左上)移动
“01” 表示向东北(右上)移动
“10” 表示向西南(右下)移动
“11” 表示向东南(坐下)移动
ref: ssh-keygen 中生成的 randomart image 是什么 | 周小鱼のCODE_HOME (zhoulingyu.com)
妹子网站主题很漂亮, 可惜下一秒就是我的了
iissnan/hexo-theme-next: Elegant theme for Hexo. (github.com)
Adding a new SSH key to your GitHub account
添加ssh key这个过程, 网上的教程都是用浏览器完成的
这里也就用浏览器做这个, 用资源管理器访问ubuntu
\\wsl$
把ssh key 内容文件拷贝到githhub账户上吧
然后访问github, 进入setting > New SSH key
粘贴那个ssh key就可以了!
有.pub后缀的才是公钥!
Testing your SSH connection
-
确认执行过上面两步后, 执行下面的的命令
$ ssh -T git@github.com # Attempts to ssh to GitHub > The authenticity of host ‘github.com (IP ADDRESS)‘ can‘t be established. > RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. > Are you sure you want to continue connecting (yes/no)? -
然后确认指纹fingerprint :
These are GitHub‘s public key fingerprints:
SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8(RSA)SHA256:br9IjFspm1vxR3iA35FWE+4VTyz1hYVLIE2t1/CeyWQ(DSA)
-
如果指纹匹配了, 输入yes 确认:
> Warning: Permanently added ‘github.com (IP ADDRESS)‘ (RSA) to the list of known hosts. > Hi username! You‘ve successfully authenticated, but GitHub does not provide shell access.如果出现错误信息
> ... > Agent admitted failure to sign using the key. > debug1: No more authentication methods to try. > Permission denied (publickey).这是个已知的出现于linux系统中的常见问题, 见帮助文档 Error: Agent admitted failure to sign - GitHub Docs
-
最后确认欢迎信息中的username是否相同.
收到"permission denied"时, 见帮助文档Error: Permission denied (publickey) - GitHub Docs
git push
$ git init
$ git remote add origin *https origin*
$ git commit -m ‘first commit‘
$ git push -u origin master
然后现在用户名登陆的方法不行了
换ssh登陆
$ git remote -v
> origin https://github.com/*** (fetch)
> origin https://github.com/*** (push)
$ git remote add origin git@github.com:*username:projectname*
添加coc-config和vimrc之后即可push
$ git push origin master
[master (root-commit) c6f59b1] first commit
Committer: usr <usr@com.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
3 files changed, 820 insertions(+)
create mode 100644 README
create mode 100644 coc-settings.json
create mode 100644 vimrc
$ git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 9.75 KiB | 9.75 MiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for ‘master‘ on GitHub by visiting:
remote: https://github.com/usr/vim/pull/new/master
remote:
To github.com:usr/vim.git
* [new branch] master -> master
下载好.ttf后缀的字体文件放入C:/windows/Fonts 目录中 ??
至关重要 , 而且必须选择Mono等宽字体 ??
https://www.itranslater.com/qa/details/2582439887127446528 ??
原文:https://www.cnblogs.com/Ik4ruga/p/15200435.html