AstroNvim

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 (opens in a new tab)

Initial Setup

Follow the instruction (opens in a new tab), 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 (opens in a new tab).

I read 开始使用 AstroNvim (opens in a new tab) to gain the first impression of astronvim. Then referenced these two repositories for the configuration.

Keymaps Need to Know

full keymap list (opens in a new tab)

  • currently, Leader key is set to the Space key, you can see many options after pressing the Leader 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 use ctrl + w twice to switch between windows
  • Find files Leader + ff
  • Comment Leader + /
  • :wa to save all
  • ? to show help in file explorer
  • Leader + uw to toggle text wrap

buffer

  • Next Buffer ]b
  • Previous Buffer [b
  • Close Buffer Leader + c

Terminal

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" (opens in a new tab).

kanagawa-paper.nvim https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/colorscheme/kanagawa-paper-nvim (opens in a new tab)

I'll use the good old gruvbox-nvim (opens in a new tab)

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 (opens in a new tab), don't get it wrong

Maybe one day I'll try flexoki (opens in a new tab), and create a community package!(just saying...)

Custom Plugin

I installed github/copilot.vim (opens in a new tab)

From astronvim documentation (opens in a new tab), 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.

Summary

I love astronvim, it made me return(or start) to vim! Thanks to the authors and contributors, and Mr. Yuanji (opens in a new tab), I read your blog and it helps me a lot!

Next time I should get git work. blame, diff, and so on.

Do not shoot this.