Config Vim
1. 安装 anaconda
本来安装 anaconda 应该问题不大,但是却发现了一个问题。
./Anaconda3-2021.11-Linux-x86_64.sh: 489: [[: Exec format error
这个错,是因为
直用./Anaconda.sh 启动安装默认用的是 sh 改成了 bash Anaconda.sh 就不会报错了.
2. 一些碎的 Linux 知识
2.1. 查找包的安装位置
一些软件用 apt install 了,但是不知道安装位置在哪里 dpkg -L xxx
显示包的安装位
置.
2.2. 编译错误定位
编译的时候,打印一些 log 但是并不详细一般会有更加详细的编译 log 文件,在里面可以 更精确的定位错误发生的原因.
2.3. linux 的环境变量可能是两个
LIBRARY_PATH
编译的时候用到的库的搜索路径 LD_LIBRARY_PATH
程序加载时库的搜索路
径
2.4. 遇到一个问题明明再搜索路径下有动态库,却报错所无法找到
okular: error while loading shared libraries: libQt5Core.so.5: cannot open shared object file: No such file or directory 用 strip 处理完之后解决 sudo strip –remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
3. 编译 vim
apt 安装的 vim 不能随意的控制 vim 的特性,比如在 latex 反向搜索的时候需要的 +clietservice。 apt-cache search libc-dev ln -s libXtst.so.6 libXtst.so 综合两篇 博客。 https://www.jianshu.com/p/aa5ea81bbc72 https://toutiao.io/posts/runvgs/preview 尽量多的保留特性,最终得到的 config 命令 是
1 | ./configure --with-features=huge \ |
--enable-fail-if-missing
用于显示错误信息。
3.1. 很久没有成功,最后 apt 安装解决了
编译的时候 feature 用了 hug,但是还是没有增加+clientserver。我估计是缺少库。查
src/auto/cofig.log 也没有发现很相关的信息。最后sudo apt-get install vim-gtk
成
功安装了+clientserver 的 vim。
4. tmux
To enable vi key mode in tmux. I mapped hjkl
for select the pane.
1 | bind -r 'h' select-pane -L # move left |
r
means I can change the pane continually by click <prefix>
and twice k
.
5. A practice of vim
5.1. Search and Replace
:.,$s/old/new/gc
, where g
means match all for each line and c
means ask me
before replace at each position. Without g
only the first match of each line
will be considered.
6. Why lua instead of vimL(vim script)
6.1. Introduction
Neovim has an embedded lua 5.1 runtime which is used to create faster and more powerful extentions of you favorite efitor.
- VimL is a slow interpreted language with almost no optimizations. Much of the time spent in vim startup and in actions from plugins that can block the main loop in the editor is in parsing and executing vim script.
6.2. How to use lua in command line or vimL file
see :h lua
.
- From the vim command line, you can run
lua <you code>
. This is useful for keybindings, commands, and other one-off execution cases. - Inside of a vimL file, you can demarcate lua code with the follow code fencing:
1 | lua << EOF |
- Inside of a vimL file you can use the
lua
keyword to execute commands similar to the first example,i.e.,lua <your code>
.
One important note here is that Neovim will look for lua code in the
runtimepath
you’ve set in your settings. Additionally, it will append your
runtimepath with /lua/?.lua
and lua/?/init.lua
so it is common practice to
see a /lua
sub-directory inside nvim
. For more detailed information about
where Neovim looks for lua code, check out :h lua-require
.
7. Debug vim
:message/:mes
will display the messages that your configuration files print.:nmap
or:imap
can check all the shortcuts of normal or insert mode.:map
lists the shortcuts of all modes. However, I find that some shortcuts defined can not be find by:map
.
8. A Practice for Neovim-from-scratch
8.1. Install
- Plugins are defined in
~/.config/nvim/lua/user/plugins.lua
. The plugins will fail to be installed due to the internet of China Mainland. Thus, git is asked to be configured with ssh. Then the path of plugins can be changed by addgit@github.com:
before the original path. treesitter
is a plugin for syntax-hight. It will install a series of language parsers. They are defined in~/.config/nvim/lua/user/treesitter.lua
. By settingensure_installed = {'astro', 'xxx'}
, we can define the parsers to be download. Also, download errors may be occurred due to the internet. The path of these language parsers are defined in~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/lua/nvim-treesitter/parsers.lua
, which may be changed by download with ssh.
8.2. Analysis
-
There are 21 files required in
init.lua
. They are exactly the 21 files inlua/user
folder. About 34 plugins are defined inplugins.lua
. The lua files are all the configuration file of the plugins defined inplugins.lua
, except forkeymaps.lua
,option.lua
,autocommand.lua
.plugins.lua
itself is the configuration file ofpacker.nvim
, a plugin manager. -
Here gives a brief look at the plugins.
packer.nvim
is a plugin manager.Alpha-vim
is a plugin used by Neovim-from-scratch. It allow one to custom the greeter for neovimpopup.nvim
, An implementation of the Popup API from vim in neovim.plenary.nvim
, implement some useful window management items for neovim.nvim-autopais
A super powerful auto pair plugin for neovim that supports multiple characters.Comment.nvim
Smart and Powerful commenting plugin for neovim.nvim-web-devicons
A lua fork ofvim-devicons
. This plugin provides the same icons as well as colors for each iconnvim-tree-lua
A file explorer for neovim written in lua.bufferline.nvim
A snazzy buffer line (with tabpage integration) for neovim built using lua.vim-bbye
Bbye allows you to do delete buffers (close files) without colosing you windows or messing up your layout.lualine.nvim
A blazing fast and easy to configure neovim status line written in lua.toggleterm.nvim
A neovim plugin to persist and toggle multiple terminals during an editing session.project.nvim
an all in one neovim plugin written in lua that provides superior project management.impatient.nvim
speed up loading lua modules in neovim to improve start up time.indent-blankline.nvim
adds indentation guides to all lines (including empty lines.)FixCursorHold.nvim
This is needed to fix lsp doc highlight.which-key.nvim
a lua plugin that displays a popup with possible key bindings of the command you started typing.darkplus.nvim
color themesnvim-cmp
The completion plugincmp-buffer
buffer completionscmp-path
path completionscmp-cmdline
cmdline completionscmp_luasnip
snippet completions.cmp-nvim-lsp
nvim-cmp source for neovim’s built-in language server client.LuaSnip
snippet enginfriendly-snippets
a bunch of snippets to usenvim-lspconfig
A collection of common configurations for neovim’s built-in language server clinet. Features: go-to-definition, find-references, hover, completion, rename, format, refactor.nvim-lsp-installer
allows you to seamlessly install LSP server locally(inside:echo stdpaht("data")
)nlsp-settings.nvim
A plugin to configure LSP using json/yaml files likecoc-setting.json
null-ls.nvim
for formatters and linters, use neovim as a language server to inject LSP diagnostic, code actions, and more via luatelescope.nvim
a highly extendable fuzzy finder over lists.nvim-treesitter
both provide a simple and easy way to use the interface fortree-sitter
in neovim and to provide some basic functionality such as highlighting based on it.nvim-ts-context-commentstring"
settingcomment string
option based on the cursor location in the file. The location is checked via treesitter queries.gitsigns.nvim
Git
-
The plugins are installed in
~/.local/share/nvim/site/pack/packer/start
, which is defined in theinstall_path
inplugins.lua
.
9. Analyze LunarVim
9.1. The Install Script install.sh
25 functions are defined in install.sh
.
1 | __attempt_to_install_with_cargo |
The last line main "$@"
shows that it well execute the main
function first.
$@
means that all the args will be passed to the function.
9.1.1. Function main
1 | function main() { |
9.1.2. Function clone_lvim
1 | function clone_lvim() { |
9.1.3. Function setup_lvim
1 | function setup_lvim() { |
9.1.4. Function setup_shim
1 | function setup_shim() { |
The ~/.local/bin/lvim
is
1 |
|
9.1.5. Function msg
Message or log is an effective tool to debug and make the users know the detail
of the programming. Instead of simply using print/echo
function, most
programmers define their message functions to enable effective message giving.
Have a look at this message function.
1 | function msg() { |
9.2. ABout the init process
9.2.1. The init.lua
1 | -- init_path = '~/.local/share/lunarvim/lvim/init.lua' |
9.2.2. The Bootstrap:init
1 | ---Initialize the `&runtimepath` variables and prepare for startup |
9.2.3. The config
function in builtin
folder
For some plugins, such as whichkey
and telescope
, there are M.config
functions in their configuration files. However, the setup
function only uses
some variable defined in them and do not execute them first. The are executed by
the init.lua
in the builtin
folder.
1 | function M.config(config) |
During the lunch process, the config
functions will be called in front of the
functions defined in the configuration file config.lua
.
9.3. The nerd-fonts
The font is only related to your local devices. It is not related to the remote device.
To install the nerd fonts, you need to download the nerd version of your fonts,
for example I use hack
, though
this or
this. Then put it in your font
directory. For windows, it is C:\Windows\Fonts
. Finally, restart your terminal
and set your terminal such as mobaxterm to use that font.
9.4. Debug system
9.4.1. lvim.log
- The file is in
~/.cache/
which is defined by~/.local/share/lunarvim/lvim/lua/lvim/core/log.lua
. UsingLog:warn/debug
will write logs in the file. lvim.log.level
controls the level that will be print into thelvim.log
(seelocal log_level = Log.levels[(lvim.log.level):upper() or "WARN"]
in thelog.lua
.function Log:get_path()
sets the path and name of the log file.log.lua
usedstructlog
which is a plugin of nvim defined in theplugins.lua
. In the readme ofstructlog
:structlog
makes logging in lua less painful and more powerful by adding structure to your log entries.
9.5. Plugins
9.5.1. yank
In the visual mode of lunarvim
, y
will yank the select chars into the system
clipboard automatically. Do not use "+Y
, which will yank the whole line.
"[~+]y
is also available.
9.5.2. project.nvim
If open vim in a subdirectory of a git package, and then open a new tmux pane or
window, its initial path will be the main directory of that git package. The
manual mode
in ~/.local/share/lunarvim/lvim/lua/lvim/core/project.lua
determines vim change the directory or not.
9.5.2.1. With lsp
In the readme of project
.
Automagically cd to project directory using nvim lsp. If not then uses pattern matching to cd to root directory
This means that lsp has the function to find the project directories.
9.5.3. Telescope
The telescope
is depended on fd
. To install fd
do not use
apt install fdclone
which causes a collapse of nvim when run telescope
.
9.5.3.1. Telescope in which key
~/.local/share/lunarvim/lvim/lua/lvim/core/which-key.lua
defines many which
key mapping related to telescope. telescope.builtin
(see the document of
telescope). <leader>sf
can find the files in current directory.
9.5.4. Comment
An error occur with Comment
when open lvim
, which is solved by adding
tag = 'v0.6',
to the plugins.lua
file the Comment part.
9.5.5. Treesitter
9.5.5.1. Parsers install
11 parsers are defined to be installed in ~/.config/lvim/config.lua
Parsers often failed to be downloaded. See
https://github.com/nvim-treesitter/nvim-treesitter#adding-parsers
. One can
download it manually. And change the url of the parsers.
parser for every language need to be generated via
tree-sitter-cli
fromgrammer.js
file, then complied to a.so
library that needd to be placed in neovim’sruntimepath
(typically underparser/{language}.so
). To simplify this,nvim-treesitter
provides commands to automate this process. If the language is already supported bynvim-treesitter
you can install it withTSInstall <language>
The {language}.so
files are in
~/.local/share/lunarvim/site/pack/packer/start/nvim-treesitter.git/parser
.
9.5.5.2. An Error May Occur When using aerial
When using aerial, and open a markdown file a error may be occur
Error executing vim.schedule lua callback: ...c/.local/share/nvim/runtime/lua/vim/treesitter/query.lua:172 : query: invalid field at position 122
.
This is solved by remove the parser of markdown in the parser folder.
9.5.6. About packer
-
the some plugins are installed in
opt
directory. Some are installed instart
directory. This is controlled by the settings inplugins.lua
. 7 plugins are installed inopt
directory, 6 of which are settedevent
and only the 6 plugins are setted it.lua-dev
is settedmodule
.module = string or list – Specifies lua module name for require. When requiring a string which starts with one of these module names, the plugin will be loaded.
event = string or list, – Specifies auto command events which load this plugin
In the Readme of
Packer
use
takes either a string or a table. If a string is provided, it is treated as a plugin location (link) for a non-optional plugin with no additional configuration.start
packages are always available and loaded every time you start nvim, whileopt
packages are loaded on-demand with thepackadd
command. This is whatpacker
uses to conditionally load plugins.packer
itself doesn’t run any code until you callrequire('packer')
, so it should be fine to keep it as a start package.
9.5.7. LSP
9.5.7.1. The setup process
- the setup function of a lsp server is defined by the files in
~/.local/share/lunarvim/site/after/ftplugin
.ftplugin
directory means file type plugin. Vim will auto load this directory when it is in the runtime path. However, only thefiletype.lua/vim
will be loaded when open a file of particular filetype.~/.local/share/lunarvim/site/after/ftplugin
is created by~/.local/share/lunarvim/lvim/lua/lvim/lsp/templates.lua
(see line 67). The server list is given in line 58. The content in the files in ftplugins is given in line 40. Theft.lua
will calllvim.lsp.manager
which is a function defined in~/.local/share/lunarvim/lvim/lua/lvim/lsp/manager.lua
. It setup the lsp servers since whenft.lua
is removed, the lsp server will not start. - The configuration files of
nvim-lspconfig
are listed in~/.local/share/lunarvim/site/pack/packer/start/nvim-lspconfig.git/lua/lspconfig/server_configurations
. Which can be modified. - The servers installed by
lsp-installer
are installed in~/.local/share/nvim/lsp_servers
- see
setup
function inmanager.lua
1 | function M.setup(server_name, user_config) |
From the code we know that most of the servers will be setup by
nvim-lsp-installer
(see requested_server:setup(config)
). However, thought
this the configuration for manually setup server is not works. From the document
of nvim-lsp-installer
,
server.setup
is deprecated. Thus I change the setup
function in manager.lua
.
1 | function M.setup(server_name, user_config) |
9.5.7.2. the relationship between lspconfig
and null-ls
- Both of them can use
latexindent
to format the tex file lspconfig
can not useprettier
.
Thus null-ls
provide an extension tools for lspconfig
. When lspconfig
can
match our requirement, we do not need to use null-ls
, e.g., tools for tex
file.
9.5.7.3. the relationship between lspconfig
and lsp-installer
lsp-installer
depends onlspconfig
as in the readme oflsp-installer
.- lvim strives to have support for all major languages. This is made possible
by plugins such as
nvim-lspconfig
, for LSP support, andnull-ls
to provide support for handing external formatters, such asprettier
andeslint
.
lua print(vim.inspect(vim.lsp.buf_get_clients()[2].resolved_capabilities))
see
the detail of server clients.
9.5.7.4. Code Action
Code action = quick fixes and refactoring
9.5.8. The lualine
The status line is defined in
~/.local/share/lunarvim/lvim/lua/lvim/core/lualine/init.lua
line 5 which can
be chose as default
, lvim
, or none
. The are defined in the
~/.local/share/lunarvim/lvim/lua/lvim/core/lualine/styles.lua
file. The
component are defined in
~/.local/share/lunarvim/lvim/lua/lvim/core/lualine/components.lua
.
9.5.9. The whichkey
Which key can define key mappings for vim. They are defined in
~/.local/share/lunarvim/lvim/lua/lvim/core/which-key.lua
. The use of
telescope
can be learned by reading which-key.lua
, since the key mapping of
telescope
is defined in it.
The lsp also used which key, which is defined in
~/.local/share/lunarvim/lvim/lua/lvim/lsp/config.lua
and used/registered in
~/.local/share/lunarvim/lvim/lua/lvim/lsp/init.lua
. Which key makes the key
mappings more organized.
9.5.9.1. Modify which key map
To modify which key maps, for example, <leader>sp
is defined in
whichkey.lua
. I want to change it in config.lua
.
lvim.builtin.which_key.mappings["sp"] = { "<CMD>Telescope projects<CR>", "Project" }
does not work.
lvim.builtin.which_key.mappings.s["p"] = { "<CMD>Telescope projects<CR>", "Project" }
works. lvim.builtin.which_key.mappings.s
is a table, and the config
function
in which-key.lua
is executed in front of the config.lua
. So that the value
of key p
can be modified.
9.5.10. The alpha
The start cover is defined in
~/.local/share/lunarvim/lvim/lua/lvim/core/alpha/startify.lua
.
9.5.11. nvim-notify
The notation manager and message manager for nvim.