Published on

AstroNvim Install and Config (Based on Ubuntu)

Authors

AstroNvim Install and Config (Based on Ubuntu)

zsh (optional)

sudo apt-get install zsh -y
chsh -s /bin/zsh
reboot

reboot or open a new terminal

oh my zsh (optional)

sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

1. Install Neovim

sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt-get update -y
sudo apt-get install neovim -y

2. Install Xclip

sudo apt-get install xclip

3. Back up nvim

mv ~/.config/nvim ~/.config/nvim.bak
mv ~/.local/share/nvim ~/.local/share/nvim.bak
mv ~/.local/state/nvim ~/.local/state/nvim.bak
mv ~/.cache/nvim ~/.cache/nvim.bak

4. Clone AstroNvim Repository and Start

git clone --depth 1 https://github.com/AstroNvim/template ~/.config/nvim
rm -rf ~/.config/nvim/.git
nvim

5. Key Mappings Config

nvim ~/.config/nvim/lua/plugins/mappings.lua

Append the below code to mappings.lua

return {
  {
    "AstroNvim/astrocore",
    ---@type AstroCoreOpts
    opts = {
      mappings = {
        -- first key is the mode
        n = {
          -- second key is the lefthand side of the map
          -- mappings seen under group name "Buffer"
          ["<Leader>bn"] = { "<cmd>tabnew<cr>", desc = "New tab" },
          ["<Leader>bD"] = {
            function()
              require("astroui.status").heirline.buffer_picker(function(bufnr)
                require("astrocore.buffer").close(bufnr)
              end)
            end,
            desc = "Pick to close",
          },
          -- tables with just a `desc` key will be registered with which-key if it's installed
          -- this is useful for naming menus
          ["<Leader>b"] = { desc = "Buffers" },
          -- quick save
          -- ["<C-s>"] = { ":w!<cr>", desc = "Save File" },  -- change description but the same command
        },
        t = {
          -- setting a mapping to false will disable it
          -- ["<esc>"] = false,
        },
      },
    },
  },
  {
    "AstroNvim/astrolsp",
    ---@type AstroLSPOpts
    opts = {
      mappings = {
        n = {
          -- this mapping will only be set in buffers with an LSP attached
          K = {
            function()
              vim.lsp.buf.hover()
            end,
            desc = "Hover symbol details",
          },
          -- condition for only server with declaration capabilities
          gD = {
            function()
              vim.lsp.buf.declaration()
            end,
            desc = "Declaration of current symbol",
            cond = "textDocument/declaration",
          },
        },
      },
    },
  },
}

Your personal vim key mappings may conflict with some mappings in astronvim

You can view the following files:

nvim ~/.local/share/nvim/lazy/AstroNvim/lua/astronvim/plugins/_astrocore_mappings.lua

6. Theme

modify the community.lua file:

nvim ~/.config/nvim/lua/community.lua

append the following code:

 { import = "astrocommunity.colorscheme.catppuccin" }

local lazypath = vim.env.LAZY or vim.fn.stdpath "data" .. "/lazy/lazy.nvim"

For more details, please visit https://github.com/AstroNvim/astrocommunity

modify the astroui.lua, set your theme

nvim ~/.config/nvim/lua/plugins/astroui.lua

image-20250105170817917

7.Remote Server Clipboard

When we use SSH to login to a remote server(like ubuntu), our AstroNvim clipboard may not sync with the clipboard of our local machine. In this case, we can use OSC 52. Then , we can use y to copy content from our AstroNvim on the remote server to the local machine, and use Ctrl + V to paste content into AstroNvim from the local machine to remote server.

The solution is:

vim ~/.config/nvim/init.lua

append the following code to init.lua

vim.o.clipboard = "unnamedplus"

local function paste()
  return {
    vim.fn.split(vim.fn.getreg(""), "\n"),
    vim.fn.getregtype(""),
  }
end

vim.g.clipboard = {
  name = "OSC 52",
  copy = {
    ["+"] = require("vim.ui.clipboard.osc52").copy("+"),
    ["*"] = require("vim.ui.clipboard.osc52").copy("*"),
  },
  paste = {
    ["+"] = paste,
    ["*"] = paste,
  },
}

For more details, please visit: https://neovim.io/doc/user/provider.html#clipboard-tool