kickstart.nvim
首先,kickstart.nvim 这个配置版本已经不是我的默认使用版本。
This is going to be the 2nd video I tried to follow through and learn something new about Neovim.
已经事先安装了 Neovim 的默认版本,这里再继续安装另外一个配置,同时记录如何在同一台机器上并行保存多个 Neovim 配置。
What is kickstart.nvim
Not a Neovim distribution, but instead a starting point for your configuration with Lua, in one single init.lua
file.
Prerequisites
- Some basic understanding about Lua
:help lua-guide
:echo $MYVIMRC
Installation
My default Neovim's configurations are located in path $env:LOCALAPPDATA\nvim\
and there are currently two files:
coc-settings.json
init.vim
This version is named default version.
接下来尝试安装 nvim-kickstart,在 PowerShell 运行如下命令:
git clone https://github.com/nvim-lua/kickstart.nvim.git $env:LOCALAPPDATA\nvim\
出现报错信息:
fatal: destination path 'C:\Users\Alowr\AppData\Local\nvim' already exists and is not an empty directory.
这是因为,当前目录已经安装了一个 Neovim 的默认版本,给定的安装目录不为空,无法再安装另外一个配置版本。
我们可以选择将安装目录的已有配置文件移走备份:
coc-settings.json
init.vim
重新运行 clone 命令,则将 kickstart.nvim 项目克隆至安装目录。
After installation, we can see that total 9 objects have been cloned into the destination location, 4 folders and 5 files.
平行安装多个配置版本
我可以与 kickstart 并行保留我的现有配置吗?
可以!你可以在 PowerShell 使用 $env:NVIM_APPNAME=nvim-NAME
来维护多个配置。例如,你可以在 ~/AppData/Local/nvim-kickstart
中安装 nvim-kickstart
配置,并在 PowerShell 配置文件内创建短命令 kv
和 lv
:
# Functions to launch different Neovim configurations in PowerShell
function kv {
$env:NVIM_APPNAME = "nvim-kickstart"
nvim
}
function lv {
$env:NVIM_APPNAME = "nvim-lazyvim"
nvim
}
保存配置文件,重启 PowerShell,运行 kv
就可以运行 nvim-kickstart
配置版本,运行 lv
就可以运行 nvim-lazyvim
配置版本。
但是需要注意,在运行过上述短命令之后,相当于 PowerShell 在当前 Session 之内修改了环境变量,导致 Neovim 的默认路径已经改变。若要恢复默认的 Neovim 路径,需要重启 PowerShell 才行。
添加选择界面
在 PowerShell 运行 .code $PROFILE
打开 PowerShell 配置文件,添加以下代码,以增加选择 Neovim 配置版本的界面:
# Function to select different Neovim configurations interactively
function nvims {
$items = @("default", "nvim-lazyvim", "nvim-kickstart")
$config = $items | fzf --prompt=" Neovim Config " --height=50% --layout=reverse --border
if (-not $config) {
Write-Output "Nothing selected"
return
} elseif ($config -eq "default") {
$env:NVIM_APPNAME = ""
} else {
$env:NVIM_APPNAME = $config
}
nvim
}
配置选项界面,菜单设置 default、nvim-kickstart、nvim-lazyvim 三个选项。
想要了解更多,参考 NVIM_APPNAME
nvim-kickstart
以下选择运行 nvim-kickstart 配置,来更多的熟悉一下这个配置版本。
运行报错:
no c compiler found! "cc", "gcc", "clang", "cl", "zig" are not executable.
通过 choco 安装 zig 失败:
choco install zig
更换使用 winget 安装 zig 成功:
winget install -e --id zig.zig
重新进行 nvim-kickstart 便不再报错。
运行 :checkhealth
可以看到 zig 已经成功安装。
neo-tree
Next step is to get a NRRDTree similar plugin to work with nvim-kickstart configuration. The good news is that you have neo-tree available. Just uncomment require 'kickstart.plugins.neo-tree',
in your init.lua
file and run :Neotree
in Neovim to bring out the sidebar.
Press ?
in the Neo-tree window to view the list of mappings.
Can I assign a key mapping <C-t>
to this command? You dont' have to, because neo-tree has its own key mappings that are different from NERDTree. Use \
to toggle the sidebar on/off.
Where are the settings for neo-tree plugin? Are there any default settings from the lazy.nvim plugin manager?
If you have cloned the kickstart.nvim repository, the neo-tree plugin is built-in, so just uncomment in your init.lua file and it works immediately. The keymaps \
are defined here ~\AppData\Local\nvim-kickstart\lua\kickstart\plugins\neo-tree.lua
in this file.
require 'kickstart.plugins.neo-tree',
Just wanted to revise from \
to <leader>E
or <leader>E
for the sidebar toggle. Because nvim-lazyvim has this shortcut built-in as default and it's quite convenient after sometime of using it.
查看当前配置
Run command :echo stdpath("config")
in Neovim will print the path of nvim configuration that is currently running, whether it is the default, nvim-kickstart or nvim-lazyvim. For instance, when running command :echo stdpath("config")
in nvim-kickstart, the path of the current Neovim C:\Users\Alowr\AppData\Local\nvim-kickstart
will be printed to the standard output.
In either configuration, to bring up the config file, just run :e $MYVIMRC
command, which will open ~\AppData\Local\nvim-kickstart\init.lua
for you to review and edit.
Just note, nvim-kickstart has one init.lua
file, while the others have init.lua
as the entry point, with many separately organized configuration files.
自动格式化
需要 Markdown 文档的自动格式化配置,默认安装完毕之后暂时缺失 Prettier 配置。参考这篇文章 How To Setup Linting & Formatting In Neovim And Replace null-ls 可以快速添加配置。
Features
- Auto bullets list in Markdowon
- Format the document when saving
- Quick save with
<leader>ww
- When formate on save, the blank newlines on the bottom of the file get removed
<leader>y
copy selected content into the system clipboard<leader>yy
copy current line into the system clipboard- Auto-complete
- checkbox
Known issues
- Customized 'H1'-'H6' header styles for Markdown, but looks ugly
- Installed `todo-comments` plugin, but how to quickly insert such todo-comments into you content
todo-comments
plugin, but how to quickly insert such todo-comments into you content - Maybe through auto-complete feature
- checkbox test
- How to revise the hint message for keymap `<leader>x`
<leader>x
- First to figure out which plugin in pulls up the menu when hitting `<leader>`
<leader>
todo-comments
Test for H2 by <leader>kk
Test of H3 by <leader>ll
Test for H4 by <leader>uu
mini.surround
Default config (copied from README file of the repo)
-- No need to copy this inside `setup()`. Will be used automatically.
{
-- Add custom surroundings to be used on top of builtin ones. For more
-- information with examples, see `:h MiniSurround.config`.
custom_surroundings = nil,
-- Duration (in ms) of highlight when calling `MiniSurround.highlight()`
highlight_duration = 500,
-- Module mappings. Use `''` (empty string) to disable one.
mappings = {
add = 'sa', -- Add surrounding in Normal and Visual modes
delete = 'sd', -- Delete surrounding
find = 'sf', -- Find surrounding (to the right)
find_left = 'sF', -- Find surrounding (to the left)
highlight = 'sh', -- Highlight surrounding
replace = 'sr', -- Replace surrounding
update_n_lines = 'sn', -- Update `n_lines`
suffix_last = 'l', -- Suffix to search with "prev" method
suffix_next = 'n', -- Suffix to search with "next" method
},
-- Number of lines within which surrounding is searched
n_lines = 20,
-- Whether to respect selection type:
-- - Place surroundings on separate lines in linewise mode.
-- - Place surroundings on each line in blockwise mode.
respect_selection_type = false,
-- How to search for surrounding (first inside current line, then inside
-- neighborhood). One of 'cover', 'cover_or_next', 'cover_or_prev',
-- 'cover_or_nearest', 'next', 'prev', 'nearest'. For more details,
-- see `:h MiniSurround.config`.
search_method = 'cover',
-- Whether to disable showing non-error feedback
slent = false,
}
Here is some faking content to (play) [around] {with} the "features" that mini.surround
has to offer. Some additional content with Strong Content and content with "quotation marks" and "single quotes", of course (notes in parenthesis), and [notes in square brackets].
Here are some example commands of how you add, delete, or replace surrounding characters:
saiw'
means [S]urround [A]add [I]n [W]ord with ['
]saiw"
means [S]urround [A]add [I]n [W]ord with ["
]saiw(
means [S]urround [A]add [I]n [W]ord with [(
], with a space each on left/right sidesaiw)
means [S]urround [A]add [I]n [W]ord with [)
]saiw[
means [S]urround [A]add [I]n [W]ord with [[
], with a space each on left/right sidesaiw]
means [S]urround [A]add [I]n [W]ord with []
]saiw{
means [S]urround [A]add [I]n [W]ord with [{
], with a space each on left/right sidesaiw}
means [S]urround [A]add [I]n [W]ord with [}
]sa4w'
means [S]urround [A]add [4] [W]ords with ['
], with last space includedsa4e'
means [S]urround [A]add [4] [W]ords with ['
]sd'
means [S]urround [D]elete for ['
]sr"'
means [S]urround [R]eplace ["
] with ['
]
Because by default s
is already a native Vim command, so you have to type sa
really fast, or it deletes a character and enters Insert mode.
Further reading on "text object selection" by :h text-objects
.
Reference resources
- https://neovim.io/doc/user/starting.html#_nvim_appname
- https://michaeluloth.com/neovim-switch-configs/
- https://www.youtube.com/watch?v=LkHjJlSgKZY
- https://medium.com/@joydeep150703/neovim-config-switcher-but-for-windows-ed6ef08d045b
- https://linkarzu.com/posts/neovim/lazyvim-vs-kickstart/
- https://blog.nikfp.com/how-to-install-and-set-up-neovim-on-windows
- https://www.youtube.com/watch?v=KYDG3AHgYEs