astronvim
This is not a step-by-step tutorial, instead, it’s a collection of notes on what I encountered while setting up and using AstroNvim.
First Link First
Official Documentation of AstroNvim
Initial Setup
Follow the instruction, install the latest Neovim.
When editing configuration files, make sure to check the top of the file. If you see a line like this, delete it.
if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
To ensure edited configuration files works correctly, the best way is to quit and start AstroNvim again.
When starting, you can return to where you were by select Recent
.
Also, astronvim has auto-format on save.
I read 开始使用 AstroNvim to gain the first impression of astronvim. Then referenced these two repositories for the configuration.
Keymaps Need to Know
- currently,
Leader
key is set to theSpace
key, you can see many options after pressing theLeader
key Leader + e
to show/hide the file explorer- move cursor(by
j
k
) to a file, press enter to open it Leader + o
to focus on the file explorer, or usectrl + w
twice to switch between windows- Find files
Leader + ff
- Comment
Leader + /
:wa
to save all?
to show help in file explorerLeader + uw
to toggle text wrap
buffer
- Next Buffer
]b
- Previous Buffer
[b
- Close Buffer
Leader + c
Terminal
Leader + tf
Toggle on Floating Terminalctrl-\
ctrl-n
leave the edit mode in terminal window, so you can toggle it off
Install LSP(Language Server Protocol)
It’s generally better to use AstroNvim community packages. I tried to install java-language-server manually by :Mason
and failed.
I installed
{ import = "astrocommunity.pack.typescript" },
{ import = "astrocommunity.pack.html-css" },
{ import = "astrocommunity.pack.java" },
{ import = "astrocommunity.pack.markdown" },
{ import = "astrocommunity.pack.mdx" },
also, you can
- use
:Mason
to open the package manager mason - if you can’t see a package list, use
g?
to toggle the help page(this is also written at the top of current Mason window) - you can use
esc
to quit current window - Install package i
- Uninstall package X
- search by keyword, for example, I use /typescript to find the typescript-language-server
everybody likes colorscheme
神奈川! Dope for this guy! or, individual, if you prefer to avoid the potentially offensive terms like “guy”.
kanagawa-paper.nvim https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/colorscheme/kanagawa-paper-nvim
I’ll use the good old gruvbox-nvim
add this line to community.lua
, it might at ~/.config/nvim/lua/community.lua
Note: gruvbox-nvim
is the name of the repository, don’t get it wrong like gruvbox
or gruvbox.nvim
{ import = "astrocommunity.colorscheme.gruvbox-nvim" },
update the colorscheme, it might at ~/.config/nvim/lua/plugins/astroui.lua
opts = {
-- change colorscheme
colorscheme = "gruvbox",
Note: gruvbox
is the colorscheme name defined in the official repository, don’t get it wrong
Maybe one day I’ll try flexoki, and create a community package!(just saying…)
Custom Plugin
Update:
I now use copilot-cmp.
Add this line to community.lua
, it might at ~/.config/nvim/lua/community.lua
.
{ import = "astrocommunity.completion.copilot-cmp" },
I want to make markdown enabled, so I created ~/.config/nvim/lua/plugins/copilot-override.lua
with content like this:
return {
"zbirenbaum/copilot.lua",
opts = {
suggestions = {
enabled = true,
},
filetypes = {
markdown = true, -- Explicitly enable markdown
},
},
}
I installed github/copilot.vim
From astronvim documentation, I learned that I needed to create a github-copilot.lua
file in plugin directory.
Initially I created a copilot.lua
file, but it messed up with the :help copilot
, so I renamed it to github-copilot.lua
.
return {
"github/copilot.vim",
-- https://github.com/orgs/community/discussions/118483
-- function body could be found in `:help copilot`
-- I modified the `J` to `j`
-- when auto complete is triggered, use Esc to turn it off, then use <C-j> to accept the suggestion
config = function()
-- use <C-j> to accept the suggestion
vim.keymap.set("i", "<C-j>", 'copilot#Accept("\\<CR>")', {
expr = true,
replace_keycodes = false,
})
vim.g.copilot_no_tab_map = true
end,
}
Save it and quit and start AstroNvim, use :Copilot
to activate it, copy the one time code, paste in the browser tab, done.
Resources
Summary
I love astronvim, it made me return(or start) to vim! Thanks to the authors and contributors, and Mr. Yuanji, I read your blog and it helps me a lot!
Next time I should get git work. blame, diff, and so on.