|
问题背景
公司配发的电脑是 macOS,日常开发需要访问 Linux 虚拟机,出于安全方面的考虑,只能通过跳板机登录。这阻止了大多数远程图形界面的使用,让写代码的工作变得复杂起来,市面上非常好用的 VSCode 都用不了。因此考虑基于 vim 搭建一套个人开发环境,需要支持以下特性:
- 语法高亮 (风格可切换)
- 自动格式化
- 函数或变量定义跳转
- 函数或变量引用跳转
- 成员函数或变量下拉列表提示
- 函数或变量 TAB 键自动补齐
- 快速查找
- ……
考察了多种方案后,决定基于目前比较流行的 neovim 来打造,不过它面向的是比较新的 Linux 发行版,不知道我这个老的 CentOS7 能不能带起来,本文就是一个探索过程。
系统环境
开始之前,先罗列下老旧系统的配置:
- 硬件
- CPU: 2.40GHz * 2 核
- 内存: 16G
- 存储: 40G + 100G
- 软件
- 系统:CentOS Linux release 7.9.2009 (Core)
- kernel:3.10.0-1160.21.1.el7.x86_64
- rpm:4.11.3
- gcc:4.8.5 (备选 8.2)
- glibc:2.17
- make:GNU make 3.82
- openssl:1.0.2k
- git:1.8
- wget:1.14
- python: 3.6.8
确实是老旧,都是公司成本控制的泪~
软件安装
整个搭建过程是比较坎坷的,常常是装了 Z 之后才发现它依赖 X、Y,去安装 X、Y 的时候又发现一坨问题……这里为了直接上手,改为正叙模式,按这个方式一步步安装、升级,应该是没问题的。如果你的系统上已经存在依赖的软件且版本一致或更新,可以忽略对应安装过程。
在 Linux 上安装软件,一般有源码安装和包管理器安装两种方式,后者在 CentOS 上就是 yum 了,然而软件源提供的软件一般版本较低,有时需要使用前者,这就比较依赖 wget、git、gcc 和 make 了,这也是在上一节中列出他们版本的原因,在开始安装各种软件之前,需要首先升级他们。
基础软件升级
gcc
系统提供的 4.8.5 编译基本是够用的,后面代码格式化需要用到的 clang-format 模块如果是源码方式安装,要求 gcc 至少是 5.1,如果你有 5.1 及以上的 gcc 那更好。没有也没关系,本文会用其它方式绕过,毕竟升级 gcc 是一项大工程,没有半天是搞不定的,太耽误功夫。
虽然不必升级 gcc,但是一些代码库使用的高版本 gcc 默认了 -std=c99 选项,这点对老版本非常不友好,为此需要特意告诉老 gcc 编译器这个选项。具体就是修改 gcc 的 spec 文件,首先是确认当前系统 gcc 加载的 spec 文件:- > strace -e file gcc 2>&1 | grep specs
- access("/usr/lib/gcc/x86_64-redhat-linux/4.8.5/specs", R_OK) = -1 ENOENT (No such file or directory)
- access("/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/lib/x86_64-redhat-linux/4.8.5/specs", R_OK) = -1 ENOENT (No such file or directory)
- access("/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/lib/specs", R_OK) = -1 ENOENT (No such file or directory)
- access("/usr/lib/gcc/x86_64-redhat-linux/specs", R_OK) = -1 ENOENT (No such file or directory)
复制代码 目前看是没有,需要使用 gcc 析出一份默认的:- > sudo bash -c 'gcc -dumpspecs > /usr/lib/gcc/x86_64-redhat-linux/4.8.5/specs'
复制代码 注意析出的路径就是上面加载路径中的第一条,内容如下:
查看代码再次运行 gcc,确认已加载修改后的 spec 文件:- > cat /usr/lib/gcc/x86_64-redhat-linux/4.8.5/specs.c99 | grep c99
- %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}} %{!iplugindir*:%{fplugin*:%:find-plugindir()}} %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{aux-info*} %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} %{g*} %{O*} %{W*&pedantic*} %{w} -std=c99 %{std*&ansi&trigraphs} %{v:-version} %{pg:-p} %{p} %{f*} %{undef} %{Qn:-fno-ident} %{Qy:} %{-help:--help} %{-target-help:--target-help} %{-version:--version} %{-help=*:--help=%*} %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}} %{fsyntax-only:-o %j} %{-param*} %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants} %{coverage:-fprofile-arcs -ftest-coverage}
复制代码 第一行的输出符合预期,整个过程可参考附录 4。
如果不进行这个设置,后面在编译 lsp-server 中的 lsp-kind.nvim & nvim-lspconfig 模块时会失败:
glibc
系统提供的 2.17 不行,clangd 需要至少 2.18,否则 neovim 中跳转相关的键 (gd/gD) 会失效,而 yum 上没有大于 2.17 版本的软件可用,需要手动更新下:- > gcc -v
- Reading specs from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/specs
- COLLECT_GCC=gcc
- COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
- Target: x86_64-redhat-linux
- Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
- Thread model: posix
- gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
复制代码 具体升级过程可参考附录 2。
make
系统提供的 3.82 GNU Make 基本够用。
openssl
系统提供的 1.0.2k 基本够用。
git
系统提供的 1.8 版本不行,需要升级到 2.38,否则不能识别 rebase=false 参数,导致插件更新时拉取代码库失败:
当时直接使用 yum install git 升级的版本还是比较低,所以我是手动安装的,但也取了个巧,直接安装了个 rpm 来更新 CentOS7 的软件源:- # 通过网盘链接下载 rpm 包
- # 链接: https://pan.baidu.com/s/1QAyqa04iZ45q1-HqeYH80Q?pwd=1234 提取码: 1234
- > ls -lh *.rpm
- -rw-r--r-- 1 yunhai01 DOORGOD 3.6M May 17 16:28 glibc-2.18-11.fc20.x86_64.rpm
- -rw-r--r-- 1 yunhai01 DOORGOD 12M May 17 16:28 glibc-common-2.18-11.fc20.x86_64.rpm
- -rw-r--r-- 1 yunhai01 DOORGOD 1.1M May 17 16:28 glibc-devel-2.18-11.fc20.x86_64.rpm
- -rw-r--r-- 1 yunhai01 DOORGOD 648K May 17 16:28 glibc-headers-2.18-11.fc20.x86_64.rpm
- > sudo rpm -Uvh --nodeps --force glibc-*.rpm
- > ldd --version
- ldd (GNU libc) 2.18
- Copyright (C) 2013 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- Written by Roland McGrath and Ulrich Drepper.
复制代码 从而找到更新版本的 git,省了不少事。后来这个源还更新了,现在安装的话是 2.43 版本。
另外最好更新 /etc/hosts 文件以便加快对 github.com 的访问速度:- > sudo yum install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
- > sudo yum install git
- > git --version
- git version 2.38.1
复制代码 这里的 ip 都是通过反查相关域名得到的,可能会有所不同,详情参考附录 3。
wget
系统提供的 1.14 版本不行,在拉取部分 lsp-server 时会出错 (cpp/lua),需要升级到 1.21.3:- > cat /etc/hosts
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 140.82.114.3 github.com
- 140.82.114.10 nodeload.github.com
- 140.82.114.6 api.github.com
- 140.82.114.10 codeload.github.com
复制代码 目前的 wget-lastest 指向的最新版本是 1.24.5。
python3
系统提供的 3.6.8 版本勉强够用,clang-format 编译安装要求 python 至少为 3.8 版本,可以选择安装 Python 3.8.1:- > curl -o wget-latest.tar.gz http://mirrors.ustc.edu.cn/gnu/wget/wget-latest.tar.gz
- > tar xvf wget-latest.tar.gz
- > cd wget-1.21.3
- > ./configure --with-ssl=openssl
- > make -j8
- > sudo make install
- > wget --version
- GNU Wget 1.21.3 built on linux-gnu.
- -cares +digest -gpgme +https +ipv6 -iri +large-file -metalink +nls
- +ntlm +opie -psl +ssl/openssl
- Wgetrc:
- /usr/local/etc/wgetrc (system)
- Locale:
- /usr/local/share/locale
- Compile:
- gcc -std=gnu11 -DHAVE_CONFIG_H
- -DSYSTEM_WGETRC="/usr/local/etc/wgetrc"
- -DLOCALEDIR="/usr/local/share/locale" -I. -I../lib -I../lib
- -DHAVE_LIBSSL -DNDEBUG -g -O2
- Link:
- gcc -std=gnu11 -DHAVE_LIBSSL -DNDEBUG -g -O2 -lpcre -lssl -lcrypto
- -lz ../lib/libgnu.a
- Copyright (C) 2015 Free Software Foundation, Inc.
- License GPLv3+: GNU GPL version 3 or later
- <http://www.gnu.org/licenses/gpl.html>.
- This is free software: you are free to change and redistribute it.
- There is NO WARRANTY, to the extent permitted by law.
- Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
- Please send bug reports and questions to <bug-wget@gnu.org>.
复制代码 不过可以通过直接下载 clang-format 来忽略这步,所以这里的 python3 没有升级,具体操作步骤在安装 clang-format 时介绍。
cargo
rust 的包管理器,系统未提供,需要单独安装:- > sudo yum install libffi-devel
- > wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
- > tar -xvf Python-3.8.1.tgz
- > cd Python-3.8.1
- > ./configure --prefix=/usr/local/python3
- > make -j8
- > sudo make altinstall
- > sudo ln -sf /usr/local/python3/bin/python3.8 /usr/bin/python3
- > sudo ln -sf /usr/local/python3/bin/pip3.8 /usr/bin/pip3
复制代码 用于后续安装 fd,它是一款 find 的替代者,可以实现更高效的文件查找,目前 yum 上最新的版本是 1.72.1。
go
go 语言编译器,系统未提供,需要单独安装:- > sudo yum install cargo
- > cargo --version
- cargo 1.65.0
复制代码 用来后续编译安装 efm-langserver,它是一款代码审查工具。目前 yum 源最新 go 版本是 1.20.12。为避免后续安装过程中出现网络访问错误的问题,可提前设置以下代理:- > sudo yum install go
- > go version
- go version go1.17.12 linux/amd64
复制代码 sqlite3
本地数据库,系统未提供,需要单独安装:- > go env -w GO111MODULE=on
- > go env -w GOPROXY=https://goproxy.io,direct
- > go env -w GOPRIVATE=*.corp.example.com
复制代码 用于后续安装 scheme ,它是一款语法高亮插件,使用 sqlite3 存储信息。
升级后
- gcc:4.8.5
- glibc:2.18
- make:GNU make 3.82
- openssl:1.0.2k
- git:2.43
- wget:1.24.5
- python: 3.6.8
- cargo:1.72.1
- go:1.20.12
- sqlite3:3.7.17
依赖软件安装
rg
全名 ripgrep,是 grep 替代者,功能更强大,不能直接使用 yum 安装,通过添加 yum 源的方式来曲线安装:- > sudo yum install sqlite sqlite-devel
- > sqlite3 --version
- 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
复制代码 源是固定的,版本目前仍保持 13.0.0。
fd
全名 fd-find,用来替代 find,功能更强大,有之前安装 cargo 的基础,直接安装:- > sudo yum-config-manager --add-repo=https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/repo/epel-7/carlwgeorge-ripgrep-epel-7.repo
- > sudo yum install ripgrep
- > rg --version
- ripgrep 13.0.0
- -SIMD -AVX (compiled)
- +SIMD +AVX (runtime)
复制代码 基于最新的 cargo 1.72.1 安装会报错:- > cargo install fd-find
- > sudo cp ~/.cargo/bin/fd /usr/local/bin/
- > fd --version
- fd 8.5.3
复制代码 看起来需要升级 rustc (1.74 > 1.72.1),不过看到要安装的 fd-find 版本为 10.1.0,好像受到了启发,直接指定 fd-find 的版本为 8.5.3 重试:- > cargo install fd-find
- Updating crates.io index
- Downloaded fd-find v10.1.0
- ...
- warning: spurious network error (3 tries remaining): [7] Couldn't connect to server (Failed to connect to 2a04:4e42:8c::649: Network is unreachable)
- Downloaded jemalloc-sys v0.5.4+5.3.0-patched
- Downloaded 64 crates (8.2 MB) in 3m 10s (largest was `linux-raw-sys` at 1.8 MB)
- error: failed to compile `fd-find v10.1.0`, intermediate artifacts can be found at `/tmp/cargo-installBfI2hZ`.
- To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
- Caused by:
- package `clap_complete v4.5.2` cannot be built because it requires rustc 1.74 or newer, while the currently active rustc version is 1.72.1
- Try re-running cargo install with `--locked`
复制代码 仍然失败,叔可忍婶不可忍,直接按提示加 --locked 选项:
查看代码- > cargo install fd-find --version 8.5.3
- Downloaded fd-find v8.5.3
- Downloaded 1 crate (114.1 KB) in 9.31s
- Updating crates.io index
- Installing fd-find v8.5.3
- Updating crates.io index
- ...
- Downloaded 22 crates (2.2 MB) in 1m 07s (largest was `linux-raw-sys` at 1013.8 KB)
- error: failed to compile `fd-find v8.5.3`, intermediate artifacts can be found at `/tmp/cargo-installmg1If6`.
- To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
- Caused by:
- package `clap_complete v4.5.2` cannot be built because it requires rustc 1.74 or newer, while the currently active rustc version is 1.72.1
- Try re-running cargo install with `--locked`
复制代码 这回成功了。尝试为之前安装失败的 10.1.0 版本增加 --locked 选项:仍然不行,看来回退 8.5.3 是唯一的解决办法。之前还探索过将 cargo 版本降为 1.65.0:- > cargo install fd-find --locked
- Updating crates.io index
- Installing fd-find v10.1.0
- Updating crates.io index
- warning: package `libc v0.2.154` in Cargo.lock is yanked in registry `crates-io`, consider running without --locked
- Updating crates.io index
- Downloaded proc-macro2 v1.0.81
- Downloaded anyhow v1.0.82
- Downloaded serde v1.0.200
- Downloaded errno v0.3.8
- Downloaded cc v1.0.96
- Downloaded syn v2.0.60
- Downloaded libc v0.2.154
- Downloaded linux-raw-sys v0.4.13
- Downloaded 8 crates (2.8 MB) in 1m 27s (largest was `linux-raw-sys` at 1.5 MB)
- error: failed to compile `fd-find v10.1.0`, intermediate artifacts can be found at `/tmp/cargo-installVoh51U`.
- To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
- Caused by:
- package `clap_builder v4.5.2` cannot be built because it requires rustc 1.74 or newer, while the currently active rustc version is 1.72.1
复制代码 未能成功。在网上也没搜到 1.65.0 的 cargo rpm 包,只能作罢。不清楚为何 1.72.1 的 cargo 要求 1.74 的 rustc,严重怀疑这是一个 bug。
书归正题,在安装完 fd 8.5.3 后需要按提示将 fd 移到 /usr/loca/bin:- > sudo yum remove cargo
- > sudo yum install cargo-1.65.0-1.el7.x86_64
- Loaded plugins: fastestmirror, langpacks, versionlock
- Loading mirror speeds from cached hostfile
- Excluding 1 update due to versionlock (use "yum versionlock status" to show it)
- No package cargo-1.65.0-1.el7.x86_64 available.
- Error: Nothing to do
复制代码 否则 neovim 找不到。
tree-sitter
是一个解析器生成工具和增量解析库,在 nvim 中主要用作 latex 语言解析器、以及 rainbow-delimiters.nvim 和 nvim-treesitter.nvim 插件的底层支持。rainbow-delimiters 主要用于多种语言的语法高亮,特别是多括号的展示;nvim-treesitter 主要用于高效代码导航与编辑,是 IDE 不可或缺的底层组件。
可以使用 cargo 安装:- > sudo cp /home/users/yunhai01/.cargo/bin/fd /usr/local/bin/
- > fd --version
- fd 8.5.3
复制代码 会遇到和安装 fd 类似的问题:
查看代码- > sudo cp /home/users/yunhai01/.cargo/bin/fd /usr/local/bin/
- > fd --version
- fd 8.5.3 Updating crates.io index Installing tree-sitter-cli v0.22.6 Updating crates.io indexwarning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation timed out after 30001 milliseconds with 0 out of 0 bytes received)warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation timed out after 30000 milliseconds with 0 out of 0 bytes received)warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation timed out after 30001 milliseconds with 0 out of 0 bytes received)warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds) Downloaded httpdate v1.0.3 Downloaded equivalent v1.0.1 Downloaded tiny_http v0.12.0 Downloaded anstyle-query v1.1.0 Downloaded ascii v1.1.0 Downloaded dirs-sys v0.4.1 Downloaded serde_derive v1.0.203 Downloaded tempfile v3.10.1 Downloaded clap_builder v4.5.6 Downloaded webbrowser v1.0.1 Downloaded tree-sitter-config v0.22.6 Downloaded tree-sitter-tags v0.22.6 Downloaded proc-macro2 v1.0.85 Downloaded percent-encoding v2.3.1 Downloaded unicode-normalization v0.1.23 Downloaded semver v1.0.23 Downloaded libloading v0.8.3 Downloaded filetime v0.2.23 Downloaded idna v0.5.0 Downloaded ahash v0.8.11 Downloaded itoa v1.0.11 Downloaded form_urlencoded v1.2.1 Downloaded zerocopy v0.7.34 Downloaded wasmparser v0.206.0 Downloaded option-ext v0.2.0 Downloaded dirs v5.0.1 Downloaded serde_json v1.0.117 Downloaded chunked_transfer v1.5.0 Downloaded ryu v1.0.18 Downloaded tree-sitter v0.22.6warning: spurious network error (3 tries remaining): [35] SSL connect error (TCP connection reset by peer) Downloaded thiserror-impl v1.0.61 Downloaded clap_lex v0.7.1 Downloaded serde v1.0.203 Downloaded unicode-bidi v0.3.15 Downloaded glob v0.3.1 Downloaded tree-sitter-loader v0.22.6 Downloaded indexmap v2.2.6 Downloaded fastrand v2.1.0 Downloaded url v2.5.0 Downloaded indoc v2.0.5 Downloaded tinyvec_macros v0.1.1 Downloaded rustc-hash v1.1.0 Downloaded clap v4.5.6 Downloaded html-escape v0.2.13 Downloaded clap_derive v4.5.5 Downloaded tree-sitter-highlight v0.22.6 Downloaded fs4 v0.8.3warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `difference v2.0.0` failed to transfer more than 10 bytes in 30s) Downloaded difference v2.0.0warning: spurious network error (3 tries remaining): [7] Couldn't connect to server (Failed to connect to 2a04:4e42:1a::649: Network is unreachable) Downloaded utf8-width v0.1.7warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `hashbrown v0.14.5` failed to transfer more than 10 bytes in 30s) Downloaded hashbrown v0.14.5warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `smallbitvec v2.5.3` failed to transfer more than 10 bytes in 30s) Downloaded smallbitvec v2.5.3warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `thiserror v1.0.61` failed to transfer more than 10 bytes in 30s) Downloaded thiserror v1.0.61warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `tinyvec v1.6.0` failed to transfer more than 10 bytes in 30s) Downloaded tinyvec v1.6.0 Downloaded 53 crates (2.7 MB) in 4m 35serror: failed to compile `tree-sitter-cli v0.22.6`, intermediate artifacts can be found at `/tmp/cargo-installFBNfkt`.To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.Caused by: package `tree-sitter-highlight v0.22.6` cannot be built because it requires rustc 1.74.1 or newer, while the currently active rustc version is 1.72.1 Try re-running cargo install with `--locked`
复制代码 增加 --locked 选项应该可以解决问题,使用 cargo 1.72.1 目前安装的版本为 0.22.6,这个版本运行依赖较高的 glibc,所以放弃。
通过官方提示的 npm 方式安装的结果也差不多:- > cargo install tree-sitter-cli
- Updating crates.io index
- Installing tree-sitter-cli v0.22.6
- Updating crates.io index
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation timed out after 30001 milliseconds with 0 out of 0 bytes received)
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation timed out after 30000 milliseconds with 0 out of 0 bytes received)
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation timed out after 30001 milliseconds with 0 out of 0 bytes received)
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (Operation too slow. Less than 10 bytes/sec transferred the last 30 seconds)
- Downloaded httpdate v1.0.3
- Downloaded equivalent v1.0.1
- Downloaded tiny_http v0.12.0
- Downloaded anstyle-query v1.1.0
- Downloaded ascii v1.1.0
- Downloaded dirs-sys v0.4.1
- Downloaded serde_derive v1.0.203
- Downloaded tempfile v3.10.1
- Downloaded clap_builder v4.5.6
- Downloaded webbrowser v1.0.1
- Downloaded tree-sitter-config v0.22.6
- Downloaded tree-sitter-tags v0.22.6
- Downloaded proc-macro2 v1.0.85
- Downloaded percent-encoding v2.3.1
- Downloaded unicode-normalization v0.1.23
- Downloaded semver v1.0.23
- Downloaded libloading v0.8.3
- Downloaded filetime v0.2.23
- Downloaded idna v0.5.0
- Downloaded ahash v0.8.11
- Downloaded itoa v1.0.11
- Downloaded form_urlencoded v1.2.1
- Downloaded zerocopy v0.7.34
- Downloaded wasmparser v0.206.0
- Downloaded option-ext v0.2.0
- Downloaded dirs v5.0.1
- Downloaded serde_json v1.0.117
- Downloaded chunked_transfer v1.5.0
- Downloaded ryu v1.0.18
- Downloaded tree-sitter v0.22.6
- warning: spurious network error (3 tries remaining): [35] SSL connect error (TCP connection reset by peer)
- Downloaded thiserror-impl v1.0.61
- Downloaded clap_lex v0.7.1
- Downloaded serde v1.0.203
- Downloaded unicode-bidi v0.3.15
- Downloaded glob v0.3.1
- Downloaded tree-sitter-loader v0.22.6
- Downloaded indexmap v2.2.6
- Downloaded fastrand v2.1.0
- Downloaded url v2.5.0
- Downloaded indoc v2.0.5
- Downloaded tinyvec_macros v0.1.1
- Downloaded rustc-hash v1.1.0
- Downloaded clap v4.5.6
- Downloaded html-escape v0.2.13
- Downloaded clap_derive v4.5.5
- Downloaded tree-sitter-highlight v0.22.6
- Downloaded fs4 v0.8.3
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `difference v2.0.0` failed to transfer more than 10 bytes in 30s)
- Downloaded difference v2.0.0
- warning: spurious network error (3 tries remaining): [7] Couldn't connect to server (Failed to connect to 2a04:4e42:1a::649: Network is unreachable)
- Downloaded utf8-width v0.1.7
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `hashbrown v0.14.5` failed to transfer more than 10 bytes in 30s)
- Downloaded hashbrown v0.14.5
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `smallbitvec v2.5.3` failed to transfer more than 10 bytes in 30s)
- Downloaded smallbitvec v2.5.3
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `thiserror v1.0.61` failed to transfer more than 10 bytes in 30s)
- Downloaded thiserror v1.0.61
- warning: spurious network error (3 tries remaining): [28] Timeout was reached (download of `tinyvec v1.6.0` failed to transfer more than 10 bytes in 30s)
- Downloaded tinyvec v1.6.0
- Downloaded 53 crates (2.7 MB) in 4m 35s
- error: failed to compile `tree-sitter-cli v0.22.6`, intermediate artifacts can be found at `/tmp/cargo-installFBNfkt`.
- To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
- Caused by:
- package `tree-sitter-highlight v0.22.6` cannot be built because it requires rustc 1.74.1 or newer, while the currently active rustc version is 1.72.1
- Try re-running cargo install with `--locked`
复制代码 最早之前安装的 0.20.7 版本是 ok 的,想通过这种方式安装的朋友,可以指定版本试一下。注意这两种方式安装后的文件分别位于 ~/.cargo/bin 和 ./node_modules/tree-sitter-cli 下,需要手动复制到 /usr/local/bin 以便生效。
现在介绍第三种安装方式,不依赖 cargo、npm 等包管理器,直接定位到 tree-sitter 官方下载页面,选择 0.20.4 版本,对于我的 CentOS7 x64 版本,选择 tree-sitter-linux-x64.gz 下载即可:- > npm install tree-sitter-cli
- added 1 package in 10m
- > ls -lh node_modules/tree-sitter-cli/
- total 25M
- -rwxr-xr-x 1 yunhai01 DOORGOD 303 Jun 7 12:13 cli.js
- -rw-r--r-- 1 yunhai01 DOORGOD 14K Jun 7 12:13 dsl.d.ts
- -rwxr-xr-x 1 yunhai01 DOORGOD 3.4K Jun 7 12:13 install.js
- -rw-r--r-- 1 yunhai01 DOORGOD 1.1K Jun 7 12:13 LICENSE
- -rw-r--r-- 1 yunhai01 DOORGOD 534 Jun 7 12:13 package.json
- -rw-r--r-- 1 yunhai01 DOORGOD 1.7K Jun 7 12:13 README.md
- -rwxr-xr-x 1 yunhai01 DOORGOD 25M Jun 7 12:23 tree-sitter
- > node_modules/tree-sitter-cli/tree-sitter --version
- node_modules/tree-sitter-cli/tree-sitter: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node_modules/tree-sitter-cli/tree-sitter)
- node_modules/tree-sitter-cli/tree-sitter: /lib64/libc.so.6: version `GLIBC_2.29' not found (required by node_modules/tree-sitter-cli/tree-sitter)
- node_modules/tree-sitter-cli/tree-sitter: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node_modules/tree-sitter-cli/tree-sitter)
复制代码 按上一面一步步执行就安装好了,亲测高于 0.20.4 的版本就有 glibc 兼容问题 (>2.18)。
efm-langserver
实现智能 IDE 的核心,基于 go 语言开发,使用 go 编译安装:- > gunzip tree-sitter-linux-x64.gz
- > chmod u+x tree-sitter-linux-x64
- > sudo mv tree-sitter-linux-x64 /usr/local/bin
- > tree-sitter --version
- tree-sitter 0.20.4 (714bfd47a744ab44b904375c177a24c0614ef49c)
复制代码 安装后没有找到 efm-langserver,经查,go 1.20 之后,需要通过 GOPATH 环境变量来指定安装目录:- > export GOPATH=/ext/tools> gunzip tree-sitter-linux-x64.gz
- > chmod u+x tree-sitter-linux-x64
- > sudo mv tree-sitter-linux-x64 /usr/local/bin
- > tree-sitter --version
- tree-sitter 0.20.4 (714bfd47a744ab44b904375c177a24c0614ef49c)go: downloading github.com/mattn/efm-langserver v0.0.53go: downloading github.com/sourcegraph/jsonrpc2 v0.2.0go: downloading gopkg.in/yaml.v3 v3.0.1go: downloading github.com/mattn/go-unicodeclass v0.0.2go: downloading github.com/reviewdog/errorformat v0.0.0-20240311054359-739e471a49b3
复制代码 同样需要复制到 /usr/local/bin 目录以便全局生效:- > export GOPATH=/ext/tools
- > go install github.com/mattn/efm-langserver@latest
- go: downloading github.com/mattn/efm-langserver v0.0.53
- go: downloading github.com/sourcegraph/jsonrpc2 v0.2.0
- go: downloading gopkg.in/yaml.v3 v3.0.1
- go: downloading github.com/mattn/go-unicodeclass v0.0.2
- go: downloading github.com/reviewdog/errorformat v0.0.0-20240311054359-739e471a49b3
复制代码 比之前安装的版本略高一些:- > sudo cp bin/efm-langserver /usr/local/bin
- > efm-langserver -v
- efm-langserver 0.0.53 (rev: HEAD/go1.20.12)
复制代码 Font
下载可支持符号的字体,例如:Nerd Font,在 macOS 上的安装非常简单,直接双击 ttf 文件安装:
然后在 macOS 终端上指定该字体,这里我使用的是 iTerm2,其它终端大同小异:
iTerm2 有以下 UI 路径:iTerm2 -> settings -> Profiles -> Default -> Text -> Font。下面是安装带符号字体前后的对比:
状态栏很多不能显示的符号都正常了 (标签页的仍保持问号,可能是一个特殊符号 Nerd Font 不支持)。
neovim
IDE 的载体,不使用 yum 安装,原因是 yum 上目前只有 0.3 版本的 neovim,而支持现代化 IDE 核心的 packer 包管理器至少需要 0.7 版本。这里使用 curl 直接下载最新版本:- > efm-langserver -v
- efm-langserver 0.0.44 (rev: 36a4d81/go1.17.12)
复制代码 启动:- > curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
复制代码 报错:- > chmod u+x nvim.appimage
- > ./nvim.appimage
复制代码 看起来需要升级 glibc 2.29,为了避免再次更新 glibc,这里直接选择可以成功安装的 neovim 0.9.2 版本:- /tmp/.mount_nvim.aw3KspQ/usr/bin/nvim: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /tmp/.mount_nvim.aw3KspQ/usr/bin/nvim)
- /tmp/.mount_nvim.aw3KspQ/usr/bin/nvim: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by /tmp/.mount_nvim.aw3KspQ/usr/bin/nvim)
复制代码 友情提示:可以在 web 端下载后传递给虚拟机,macOS 访问 github 要比虚拟机快许多。
下载成功后,运行 nvim.appimage 可以自动释放目标文件:- > curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
复制代码 如果运行后没有产生 squashfs-root 目录,说明系统缺乏 FUSE (用户空间文件系统),需要手动释放一下:- > chmod u+x nvim.appimage
- > ./nvim.appimage
复制代码 设置到 /usr/local/bin 后就可以被全局引用了:- > ./nvim.appimage --appimage-extract
复制代码 nvimdots
IDE 的实现,按照 github 主页 README 的说明直接安装:- > sudo ln -s $PWD/squashfs-root/AppRun /usr/local/bin/nvim
- > nvim --version
- NVIM v0.9.2
- Build type: Release
- LuaJIT 2.1.1692716794
- system vimrc file: "$VIM/sysinit.vim"
- fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"
- Run :checkhealth for more info
复制代码 脚本会自动判断 neovim 版本并进行适配:- if command -v curl >/dev/null 2>&1; then
- bash -c "$(curl -fsSL https://raw.githubusercontent.com/ayamir/nvimdots/HEAD/scripts/install.sh)"
- else
- bash -c "$(wget -O- https://raw.githubusercontent.com/ayamir/nvimdots/HEAD/scripts/install.sh)"
- fi
复制代码 执行过程中会让用户进行若干选项,都按默认处理就可以了。到这里所有必需软件就都安装完成了,按任意键将进入插件的安装,具体内容在下一节介绍。
安装后的目录位于:~/.config/nvim/。注意这里不要选择 neovim 0.8.1 (说的就是我),否则后面启动插件管理器时会报错:- > bash -c "$(wget -O- https://raw.githubusercontent.com/ayamir/nvimdots/HEAD/scripts/install.sh)"
- --2024-05-24 15:32:21-- https://raw.githubusercontent.com/ayamir/nvimdots/HEAD/scripts/install.sh
- Resolving raw.githubusercontent.com... 185.199.108.133, 185.199.109.133, 185.199.111.133, ...
- Connecting to raw.githubusercontent.com|185.199.108.133|:443... connected.
- HTTP request sent, awaiting response... 200 OK
- Length: 7830 (7.6K) [text/plain]
- Saving to: ‘STDOUT’
- - 100%[======================================================================================================>] 7.65K 6.79KB/s in 1.1s
- 2024-05-24 15:32:25 (6.79 KB/s) - written to stdout [7830/7830]
- ==> This script will install ayamir/nvimdots to:
- /home/users/yunhai01/.config/nvim
- Press RETURN/ENTER to continue or any other key to abort...
- ==> Validating SSH connection...
- Do you prefer to use SSH to fetch and update plugins? (otherwise HTTPS) [Y/n]:
- ==> Checking 'git clone' preferences...
- Would you like to perform a shallow clone ('--depth=1')? [Y/n]:
- ==> Fetching in progress...
- Cloning into '/home/users/yunhai01/.config/nvim'...
- remote: Enumerating objects: 170, done.
- remote: Counting objects: 100% (170/170), done.
- remote: Compressing objects: 100% (162/162), done.
- remote: Total 170 (delta 5), reused 73 (delta 0), pack-reused 0
- Receiving objects: 100% (170/170), 108.87 KiB | 203.00 KiB/s, done.
- Resolving deltas: 100% (5/5), done.
- ==> Spawning Neovim and fetching plugins... (You'll be redirected shortly)
- ==> NOTE: Please make sure you have a Rust Toolchain installed via `rustup`! Otherwise, unexpected things may
- happen. See: https://www.rust-lang.org/tools/install.
- ==> If lazy.nvim failed to fetch any plugin(s), maunally execute `:Lazy sync` until everything is up-to-date.
- Thank you for using this set of configuration!
- - Project Homepage:
- https://github.com/ayamir/nvimdots
- - Further documentation (including executables you must install for full functionality):
- https://github.com/ayamir/nvimdots/wiki/Prerequisites
- Press RETURN/ENTER to continue or any other key to abort...
复制代码 基本无解。
开发环境搭建
框架好比是毛坯房,想要入住还得“精装修”一下,主要是安装各种插件,以及本地化配置。
插件安装
同许多 IDE 一样,vim 很多功能是通过插件实现的,插件本身需要管理,这就催生了形形色色的插件管理器,知名的有 vim-plug、Vundle;vim 进化到 neovim 之后,有两个主要的插件管理器,一个是 packer,另一个是 lazy,两个都很好用,之前 nvimdots 使用的 packer,后来更新到了 lazy,可以有效的提升 neovim 的启动速度。
lazy
书接上节,在 nvimdots 安装结束后,按任意键将启动 nvim、自动拉起插件更新:
这个界面静静等待即可,最终都能安装成功:
在 lazy 插件管理页面,输入标签后面的字符可实现跳转,例如 U 跳转到更新插件页面。
也可以直接在命令行输入 :Lazy sync 来切换到 Sync 标签:
其它也类似,不再赘述。当所有插件安装结束后,q 退出界面。与原先的 packer 界面相比:
简直像从远古社会跨进到了现代社会。退出 lazy、退出 nvim,插件安装路径位于:~/.local/share/nvim 目录下。再次进入 nvim,将看到欢迎界面:
基本功能已经可用,有几个未安装的插件将继续安装。
mason
mason 也是一个插件管理器,聚焦于 lsp 服务、dap 服务、linter 和 formatter 方向,通过它可以让 nvim 轻松支持多种编程语言的智能化展示。通过 :Mason 启动:
可以观察到系统可用的语言插件、安装成功的、安装失败的,这里主要需要处理 2 个插件的安装。
clangd
从上面的日志可以看出,安装失败的原因主要是从网络获取 clangd 包失败,这里改为手动下载:- Error executing Lua callback: ...l/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/float.lua:159: Vim(append):Error executing lua callback: ...zy/rainbow-delimiters.nvim/plugin/rainbow-delimiter
- s.lua:50: attempt to call field 'get_lang' (a nil value)
- stack traceback:
- ...zy/rainbow-delimiters.nvim/plugin/rainbow-delimiters.lua:50: in function 'attach'
- ...zy/rainbow-delimiters.nvim/plugin/rainbow-delimiters.lua:151: in function <...zy/rainbow-delimiters.nvim/plugin/rainbow-delimiters.lua:151>
- [C]: in function '__newindex'
- ...l/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/float.lua:159: in function 'mount'
- ...l/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/float.lua:75: in function 'init'
- ...al/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/init.lua:53: in function 'create'
- ...al/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/init.lua:38: in function 'show'
- ...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:38: in function 'command'
- ...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:24: in function 'cmd'
- ...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:111: in function <...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:98>
- stack traceback:
- [C]: in function '__newindex'
- ...l/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/float.lua:159: in function 'mount'
- ...l/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/float.lua:75: in function 'init'
- ...al/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/init.lua:53: in function 'create'
- ...al/share/nvim/site/lazy/lazy.nvim/lua/lazy/view/init.lua:38: in function 'show'
- ...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:38: in function 'command'
- ...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:24: in function 'cmd'
- ...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:111: in function <...hare/nvim/site/lazy/lazy.nvim/lua/lazy/view/commands.lua:98>
复制代码 解压并替换到目标目录、设置命令软链接后,重启 nvim 查看:
安装成功,如果 nvim 仍显示安装 clangd,就多重启几次,甚至重启下机器。
clang-format
查看 clang-format 错误日志:
没看出来安装失败的直接原因,这里改为手动下载:- > wget https://github.com/clangd/clangd/releases/download/18.1.3/clangd-linux-18.1.3.zip
- > mv clangd-linux-18.1.3.zip ~/.local/share/nvim/mason/packages
- > cd ~/.local/share/nvim/mason/packages
- > unzip clangd-linux-18.1.3.zip
- > cd ../bin
- > ln -s $PWD/../packages/clangd_18.1.3/bin/clangd clangd
- > ./clangd --version
- clangd version 18.1.3 (https://github.com/llvm/llvm-project c13b7485b87909fcf739f62cfa382b55407433c0)
- Features: linux+grpc
- Platform: x86_64-unknown-linux-gnu
复制代码 替换到目标目录、设置命令软链接后,重启 nvim 查看:
安装成功。如果想让 Mason 安装 clang-format,除了之前介绍的升级 python3 步骤外,还需要以下操作:- > wget -c https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-1d7ec53d/clang-format-10_linux-amd64
- > chmod u+x clang-format-10_linux-arm64
- > mkdir -p ~/.local/share/nvim/mason/packages/clang-format/bin
- > mv clang-format-10_linux-amd64 ~/.local/share/nvim/mason/packages/clang-format/bin
- > cd ~/.local/share/nvim/mason/bin
- > ln -s $PWD/../packages/clang-format/bin/clang-format-10_linux-amd64 clang-format
- > ./clang-format --version
- clang-format version 10.0.1
复制代码 最后还有两个插件 python-lsp-server & gopls 没安装成功,分别是 python 与 go 语言 lspserver,由于本文着重介绍 C/C++ 环境的搭建,这个偏离主题就不再赘述了,有需求的小伙伴可以在 nvimdots 中提问寻求帮助。
如果不想看到每次在启动时它们的报错信息,可以选择不加载它们,具体操作步骤详见配置一节。
配置
各种功能插件安装完成后,还需要修改化配置一番,为了方便调用 neovim,在 bash 启动脚本中增加以下内容:- > sudo pip3 install wheel
- # 进入 nvim
- MasonInstall clang-format
复制代码 这样就可以使用 vi 或 vim 代替 nvim 了,相当于替换了默认的 vim 编辑器,如果想调用原始的 vim 编辑器,需要输入完整路径:- alias vi=nvim
- alias vim=nvim
复制代码 在进行配置之前,首先对 nvim 进行一次自我体验,这主要是通过 :checkhealth 命令来完成,下面是完整的 checkhealth 输出:
查看代码如果有插件工作不正常、老报警告框,可以通过自检发现一些问题。
主题
启动后默认的黑色背景看着黑乎乎的不够亮快,通过快捷键 (SPACE + f + c) 调出主题切换页:
这里选择 catppuccin-latte:
好多了。不过重启后就又恢复默认了,需要修改以下 lua 配置 (~/.config/nvim/lua/core/settings.lua):-
- ==============================================================================
- hop: require("hop.health").check()
- Ensuring keys are unique ~
- - OK Keys are unique
- Checking for deprecated features ~
- - OK All good
- ==============================================================================
- lazy: require("lazy.health").check()
- lazy.nvim ~
- - OK Git installed
- - OK no existing packages found by other package managers
- - OK packer_compiled.lua not found
- ==============================================================================
- lspsaga: require("lspsaga.health").check()
- Lspsaga.nvim report ~
- - OK `tree-sitter` found
- - OK tree-sitter `markdown` parser found
- - OK tree-sitter `markdown_inline` parser found
- ==============================================================================
- luasnip: require("luasnip.health").check()
- luasnip ~
- - WARNING For Variable/Placeholder-transformations, luasnip requires
- the jsregexp library. See `:help |luasnip-lsp-snippets-transformations`| for advice
- ==============================================================================
- mason: require("mason.health").check()
- mason.nvim ~
- - OK mason.nvim version v1.10.0
- - OK PATH: prepend
- - OK Providers:
- mason.providers.registry-api
- mason.providers.client
- - OK neovim version >= 0.7.0
- mason.nvim [Registries] ~
- - OK Registry `github.com/mason-org/mason-registry version: 2024-06-07-fast-test` is installed.
- mason.nvim [Core utils] ~
- - OK unzip: `UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send`
- - OK wget: `GNU Wget 1.24.5 built on linux-gnu.`
- - OK curl: `curl 7.87.0 (x86_64-pc-linux-muslx32) libcurl/7.87.0 OpenSSL/1.1.1s zlib/1.2.12 libssh2/1.9.0 nghttp2/1.43.0`
- - OK gzip: `gzip 1.5`
- - OK gtar: `tar (GNU tar) 1.26`
- - OK bash: `GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)`
- - OK sh: `Ok`
- mason.nvim [Languages] ~
- - WARNING luarocks: not available
- - ADVICE:
- - spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- - WARNING Ruby: not available
- - ADVICE:
- - spawn: ruby failed with exit code - and signal -. ruby is not executable
- - WARNING RubyGem: not available
- - ADVICE:
- - spawn: gem failed with exit code - and signal -. gem is not executable
- - WARNING Composer: not available
- - ADVICE:
- - spawn: composer failed with exit code - and signal -. composer is not executable
- - WARNING PHP: not available
- - ADVICE:
- - spawn: php failed with exit code - and signal -. php is not executable
- - OK node: `v16.18.1`
- - OK cargo: `cargo 1.72.1`
- - WARNING julia: not available
- - ADVICE:
- - spawn: julia failed with exit code - and signal -. julia is not executable
- - OK Go: `go version go1.20.12 linux/amd64`
- - OK python: `Python 3.6.8`
- - OK java: `openjdk version "1.8.0_322"`
- - OK pip: `pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)`
- - OK python venv: `Ok`
- - OK javac: `Ok`
- - OK npm: `8.19.2`
- mason.nvim [GitHub] ~
- - OK GitHub API rate limit. Used: 1. Remaining: 59. Limit: 60. Reset: Fri 07 Jun 2024 04:40:44 PM CST.
- Install and authenticate via gh-cli to increase rate limit.
- ==============================================================================
- neoconf: require("neoconf.health").check()
- neoconf.nvim ~
- - OK **treesitter-nvim** is installed
- - OK **TreeSitter jsonc** parser is installed
- - WARNING **neodev.nvim** is not installed. You won't get any proper completion for your Neovim config.
- - OK **lspconfig** is installed
- - OK **lspconfig jsonls** is installed
- - OK **lspconfig lua_ls** is installed
- ==============================================================================
- null-ls: require("null-ls.health").check()
- - OK clang_format: the command "clang-format" is executable.
- - OK prettier: the command "prettier" is executable.
- - OK gofumpt: the command "gofumpt" is executable.
- - OK shfmt: the command "shfmt" is executable.
- - OK stylua: the command "stylua" is executable.
- - OK vint: the command "vint" is executable.
- - OK goimports: the command "goimports" is executable.
- ==============================================================================
- nvim: require("nvim.health").check()
- Configuration ~
- - OK no issues found
- Runtime ~
- - OK $VIMRUNTIME: /ext/tools/squashfs-root/usr/share/nvim/runtime
- Performance ~
- - OK Build type: Release
- Remote Plugins ~
- - WARNING "wilder.nvim" is not registered.
- - WARNING Out of date
- - ADVICE:
- - Run `:UpdateRemotePlugins`
- terminal ~
- - key_backspace (kbs) terminfo entry: `key_backspace=\177`
- - key_dc (kdch1) terminfo entry: `key_dc=\E[3~`
- - $SSH_TTY="/dev/pts/0"
- ==============================================================================
- nvim-treesitter: require("nvim-treesitter.health").check()
- Installation ~
- - OK `tree-sitter` found 0.20.4 (714bfd47a744ab44b904375c177a24c0614ef49c) (parser generator, only needed for :TSInstallFromGrammar)
- - OK `node` found v16.18.1 (only needed for :TSInstallFromGrammar)
- - OK `git` executable found.
- - OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
- Version: cc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
- - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
- OS Info:
- {
- machine = "x86_64",
- release = "3.10.0-1160.21.1.el7.x86_64",
- sysname = "Linux",
- version = "#1 SMP Tue Mar 16 18:28:22 UTC 2021"
- } ~
- Parser/Features H L F I J
- - bash ✓ ✓ ✓ . ✓
- - c ✓ ✓ ✓ ✓ ✓
- - cpp ✓ ✓ ✓ ✓ ✓
- - css ✓ . ✓ ✓ ✓
- - go ✓ ✓ ✓ ✓ ✓
- - gomod ✓ . . . ✓
- - html ✓ ✓ ✓ ✓ ✓
- - javascript ✓ ✓ ✓ ✓ ✓
- - json ✓ ✓ ✓ ✓ .
- - jsonc ✓ ✓ ✓ ✓ ✓
- - latex ✓ . ✓ . ✓
- - lua ✓ ✓ ✓ ✓ ✓
- - make ✓ . ✓ . ✓
- - markdown ✓ . ✓ ✓ ✓
- - markdown_inline ✓ . . . ✓
- - python ✓ ✓ ✓ ✓ ✓
- - query ✓ ✓ ✓ ✓ ✓
- - rust ✓ ✓ ✓ ✓ ✓
- - typescript ✓ ✓ ✓ ✓ ✓
- - vim ✓ ✓ ✓ . ✓
- - vimdoc ✓ . . . ✓
- - vue ✓ . ✓ ✓ ✓
- - yaml ✓ ✓ ✓ ✓ ✓
- Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
- +) multiple parsers found, only one will be used
- x) errors found in the query, try to run :TSUpdate {lang} ~
- ==============================================================================
- provider: health#provider#check
- Clipboard (optional) ~
- - WARNING No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.
- - ADVICE:
- - :help |clipboard|
- Python 3 provider (optional) ~
- - Using: g:python3_host_prog = "python3"
- - Executable: /usr/bin/python3
- - ERROR Command error (job=16, exit code 1): `'/usr/bin/python3' -c 'import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; print(neovim.__file__)'` (in '/home/users/yunhai01/project/baidu/netdisk/p2p-sdk-mobile')
- stderr: Traceback (most recent call last): File "<string>", line 1, in <module>ModuleNotFoundError: No module named 'neovim'
- - Python version: 3.6.8
- - pynvim version: unable to load neovim Python module
- - ERROR pynvim is not installed.
- Error: unable to load neovim Python module
- - ADVICE:
- - Run in shell: /usr/bin/python3 -m pip install pynvim
- Python virtualenv ~
- - OK no $VIRTUAL_ENV
- Ruby provider (optional) ~
- - WARNING `ruby` and `gem` must be in $PATH.
- - ADVICE:
- - Install Ruby and verify that `ruby` and `gem` commands work.
- Node.js provider (optional) ~
- - Node.js: v16.18.1
- - WARNING Missing "neovim" npm (or yarn, pnpm) package.
- - ADVICE:
- - Run in shell: npm install -g neovim
- - Run in shell (if you use yarn): yarn global add neovim
- - Run in shell (if you use pnpm): pnpm install -g neovim
- - You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim
- Perl provider (optional) ~
- - WARNING Perl version is too old, 5.22+ required
- - ADVICE:
- - See :help |provider-perl| for more information.
- - You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim
- ==============================================================================
- rainbow-delimiters: require("rainbow-delimiters.health").check()
- Custom strategies ~
- - OK Valid custom default strategy.
- - OK Valid custom strategy for 'vim'.
- - OK Valid custom strategy for 'lua'.
- - OK Valid custom strategy for 'cpp'.
- - OK Valid custom strategy for 'vimdoc'.
- - OK Valid custom strategy for 'c'.
- Custom queries ~
- - OK Valid custom default query
- - OK Valid custom query for 'javascript'
- - OK Valid custom query for 'latex'
- Custom highlight groups ~
- - OK Highlight group 'RainbowDelimiterRed' defined.
- - OK Highlight group 'RainbowDelimiterOrange' defined.
- - OK Highlight group 'RainbowDelimiterYellow' defined.
- - OK Highlight group 'RainbowDelimiterGreen' defined.
- - OK Highlight group 'RainbowDelimiterBlue' defined.
- - OK Highlight group 'RainbowDelimiterCyan' defined.
- - OK Highlight group 'RainbowDelimiterViolet' defined.
- ==============================================================================
- telescope: require("telescope.health").check()
- Checking for required plugins ~
- - OK plenary installed.
- - OK nvim-treesitter installed.
- Checking external dependencies ~
- - OK rg: found ripgrep 13.0.0
- - OK fd: found fd 8.5.3
- ===== Installed extensions ===== ~
- Telescope Extension: `aerial` ~
- - No healthcheck provided
- Telescope Extension: `frecency` ~
- - OK nvim-web-devicons installed.
- - OK ripgrep installed.
- Telescope Extension: `fzf` ~
- - OK lib working as expected
- - OK file_sorter correctly configured
- - OK generic_sorter correctly configured
- Telescope Extension: `live_grep_args` ~
- - No healthcheck provided
- Telescope Extension: `notify` ~
- - No healthcheck provided
- Telescope Extension: `persisted` ~
- - No healthcheck provided
- Telescope Extension: `projects` ~
- - No healthcheck provided
- Telescope Extension: `undo` ~
- - No healthcheck provided
- Telescope Extension: `zoxide` ~
- - No healthcheck provided
- ==============================================================================
- vim.lsp: require("vim.lsp.health").check()
- - LSP log level : WARN
- - Log path: /home/users/yunhai01/.local/state/nvim/lsp.log
- - Log size: 54 KB
- vim.lsp: Active Clients ~
- - clangd (id=1, root_dir=/home/users/yunhai01/project/baidu/netdisk/p2p-sdk-mobile)
- - null-ls (id=2, root_dir=/home/users/yunhai01/project/baidu/netdisk/p2p-sdk-mobile/project/src)
- - copilot (id=3, root_dir=/home/users/yunhai01/project/baidu/netdisk/p2p-sdk-mobile/project/src)
- ==============================================================================
- vim.treesitter: require("vim.treesitter.health").check()
- - Nvim runtime ABI version: 14
- - OK Parser: bash ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/bash.so
- - OK Parser: c ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/c.so
- - OK Parser: cpp ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/cpp.so
- - OK Parser: css ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/css.so
- - OK Parser: go ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/go.so
- - OK Parser: gomod ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/gomod.so
- - OK Parser: html ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/html.so
- - OK Parser: javascript ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/javascript.so
- - OK Parser: json ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/json.so
- - OK Parser: jsonc ABI: 13, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/jsonc.so
- - OK Parser: latex ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/latex.so
- - OK Parser: lua ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/lua.so
- - OK Parser: make ABI: 13, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/make.so
- - OK Parser: markdown ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/markdown.so
- - OK Parser: markdown_inline ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/markdown_inline.so
- - OK Parser: python ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/python.so
- - OK Parser: rust ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/rust.so
- - OK Parser: typescript ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/typescript.so
- - OK Parser: vimdoc ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/vimdoc.so
- - OK Parser: vue ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/vue.so
- - OK Parser: yaml ABI: 14, path: /home/users/yunhai01/.local/share/nvim/site/lazy/nvim-treesitter/parser/yaml.so
- - OK Parser: c ABI: 14, path: /ext/tools/squashfs-root/usr/lib/nvim/parser/c.so
- - OK Parser: lua ABI: 14, path: /ext/tools/squashfs-root/usr/lib/nvim/parser/lua.so
- - OK Parser: query ABI: 14, path: /ext/tools/squashfs-root/usr/lib/nvim/parser/query.so
- - OK Parser: vim ABI: 14, path: /ext/tools/squashfs-root/usr/lib/nvim/parser/vim.so
- - OK Parser: vimdoc ABI: 14, path: /ext/tools/squashfs-root/usr/lib/nvim/parser/vimdoc.so
- ==============================================================================
- which-key: require("which-key.health").check()
- - ERROR Failed to run healthcheck for "which-key" plugin. Exception:
- function health#check, line 25
- Vim(eval):E5108: Error executing lua ...are/nvim/site/lazy/which-key.nvim/lua/which-key/keys.lua:406: Invalid buffer id: 97
- stack traceback:
- [C]: in function 'nvim_buf_get_keymap'
- ...are/nvim/site/lazy/which-key.nvim/lua/which-key/keys.lua:406: in function 'update_keymaps'
- ...e/nvim/site/lazy/which-key.nvim/lua/which-key/health.lua:15: in function 'check'
- [string "luaeval()"]:1: in main chunk
复制代码 本来是想改 colorscheme 选项的,后来发现有个 background = dark,尝试将这个改为 light 试试,重启后默认主题自动切换为 catppuccin-latte 了,下面是主题实时切换的效果:
2 核 CPU 切换有点费劲,毕竟是老旧机器,将就看吧~
状态栏
上一节中切换主题时,好多 scheme 套件的状态栏展示有问题,黑乎乎的一块显示不清楚,这是由于状态栏使用的插件 lualine 有自己的主题,需要单独设置,由于 lualine 属于插件,它们的配置文件位置稍有不同 (~/.config/nvim/lua/modules/configs/ui/lualine.lua):- ...
- -- Set the colorscheme to use here.
- -- Available values are: `catppuccin`, `catppuccin-latte`, `catppucin-mocha`, `catppuccin-frappe`, `catppuccin-macchiato`.
- ---@type string
- settings["colorscheme"] = "catppuccin"
- -- Set it to true if your terminal has transparent background.
- ---@type boolean
- settings["transparent_background"] = false
- -- Set background color to use here.
- -- Useful if you would like to use a colorscheme that has a light and dark variant like `edge`.
- -- Valid values are: `dark`, `light`.
- ---@type "dark"|"light"
- settings["background"] = "dark"
- ...
复制代码 主要修改 require("lualine").setup 一行中 theme = 的值即可,可供选择的值参考这篇。从代码上看,对于 catppuccin-* 主题,会做状态栏的同步,所以相对要好一些,可以无脑选择。
目前 nvimdots 对老旧系统的支持已经不错了,早先我设置 blue 主题时,状态栏是这个样子:
根本没法看,通过设置 lualine 主题为 onenight 解决了这个问题:
目前已经不需要单独进行设置了。
快捷键
nvimdots 提供了很丰富的快捷键支持,一般都是三键组合,例如 +f+w 进入关键字搜索,其中 是可定义的,目前默认为空格键。
通过 :verbose nmap 可以查看所有的键映射:
想看单独的键可以在后面增加参数,例如输入 :verbose nmap gD :
常用的 gD、gd、gh、gf、gr、K 都有说明。自定义的键映射位于:~/.config/nvim/lua/core/mapping.lua
[code]local bind = require("keymap.bind")local map_cr = bind.map_crlocal map_cu = bind.map_culocal map_cmd = bind.map_cmdlocal map_callback = bind.map_callbacklocal core_map = { -- Suckless ["n|"] = map_cr("normal za"):with_noremap():with_silent():with_desc("edit: Toggle code fold"), ["n|"] = map_cu("write"):with_noremap():with_silent():with_desc("edit: Save file"), ["n|Y"] = map_cmd("y$"):with_desc("edit: Yank text to EOL"), ["n|D"] = map_cmd("d$"):with_desc("edit: Delete text to EOL"), ["n|n"] = map_cmd("nzzzv"):with_noremap():with_desc("edit: Next search result"), ["n|N"] = map_cmd("Nzzzv"):with_noremap():with_desc("edit: Prev search result"), ["n|J"] = map_cmd("mzJ`z"):with_noremap():with_desc("edit: Join next line"), ["n|"] = map_callback(function() _flash_esc_or_noh() end) :with_noremap() :with_silent() :with_desc("edit: Clear search highlight"), ["n|"] = map_cmd("h"):with_noremap():with_desc("window: Focus left"), ["n|"] = map_cmd("l"):with_noremap():with_desc("window: Focus right"), ["n|"] = map_cmd("j"):with_noremap():with_desc("window: Focus down"), ["n|"] = map_cmd("k"):with_noremap():with_desc("window: Focus up"), ["t|h"] = map_cmd("wincmd h"):with_silent():with_noremap():with_desc("window: Focus left"), ["t|l"] = map_cmd("wincmd l"):with_silent():with_noremap():with_desc("window: Focus right"), ["t|j"] = map_cmd("wincmd j"):with_silent():with_noremap():with_desc("window: Focus down"), ["t|k"] = map_cmd("wincmd k"):with_silent():with_noremap():with_desc("window: Focus up"), ["n|"] = map_cr("vertical resize -3"):with_silent():with_desc("window: Resize -3 vertically"), ["n|"] = map_cr("vertical resize +3"):with_silent():with_desc("window: Resize +3 vertically"), ["n|"] = map_cr("resize -3"):with_silent():with_desc("window: Resize -3 horizontally"), ["n|"] = map_cr("resize +3"):with_silent():with_desc("window: Resize +3 horizontally"), ["n|"] = map_cr("wq"):with_desc("edit: Save file and quit"), ["n|"] = map_cr("q!"):with_desc("edit: Force quit"), ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"), ["n|tn"] = map_cr("tabnew"):with_noremap():with_silent():with_desc("tab: Create a new tab"), ["n|tk"] = map_cr("tabnext"):with_noremap():with_silent():with_desc("tab: Move to next tab"), ["n|tj"] = map_cr("tabprevious"):with_noremap():with_silent():with_desc("tab: Move to previous tab"), ["n|to"] = map_cr("tabonly"):with_noremap():with_silent():with_desc("tab: Only keep current tab"), -- Insert mode ["i|"] = map_cmd("u"):with_noremap():with_desc("edit: Delete previous block"), ["i|"] = map_cmd(""):with_noremap():with_desc("edit: Move cursor to left"), ["i|"] = map_cmd("^i"):with_noremap():with_desc("edit: Move cursor to line start"), ["i|"] = map_cmd(":w"):with_desc("edit: Save file"), ["i|"] = map_cmd(":wq"):with_desc("edit: Save file and quit"), -- Command mode ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Left"), ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Right"), ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Home"), ["c|"] = map_cmd(""):with_noremap():with_desc("edit: End"), ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Delete"), ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Backspace"), ["c|"] = map_cmd([[=expand("%:p:h") . "/" ]]) :with_noremap() :with_desc("edit: Complete path of current file"), -- Visual mode ["v|J"] = map_cmd(":m '>+1gv=gv"):with_desc("edit: Move this line down"), ["v|K"] = map_cmd(":m ' |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|