avatarGünter Fischer

Summary

This article describes a quick and easy method to turn Neovim into a fully functional IDE using AstroNvim, a preconfigured Neovim setup that can be easily customized.

Abstract

The article begins by discussing the challenges of configuring Vim or Neovim from scratch, which can be time-consuming and require extensive research. The author then introduces AstroNvim, a Neovim configuration that works right out of the box and can be easily customized. The article provides a step-by-step guide to installing and configuring AstroNvim, including prerequisites such as installing Neovim and required plugins. The guide includes instructions for both graphical and headless modes, as well as an example of customizing AstroNvim using a personal configuration repository. The article concludes by highlighting the ease of configuring diagnostics, linters, fixers, formatters, and other features for specific languages using Astrocommunity.

Bullet points

  • Configuring Vim or Neovim from scratch can be time-consuming and require extensive research.
  • AstroNvim is a preconfigured Neovim setup that works right out of the box and can be easily customized.
  • Prerequisites for using AstroNvim include installing Neovim and required plugins.
  • The article provides a step-by-step guide to installing and configuring AstroNvim, including instructions for both graphical and headless modes.
  • Customizing AstroNvim can be done using a personal configuration repository.
  • Configuring diagnostics, linters, fixers, formatters, and other features for specific languages is easy using Astrocommunity.

Turning Neovim Into An IDE In Less Than 5 Minutes

Have you ever configured Vim (or Neovim) from scratch? I have, and it cost me a lot of time and research.

It starts with some basic settings like tabstop and shiftwidth, continues with some common keymappings and choosing the right plugin manager.

Once the plugin manager is chosen after nerve-racking hours of research, the real work begins:

  • Installing and configuring plugins for the look and feel (e.g. nerdtree or lualine)
  • Installing and configuring source code management plugins (e.g. gitgutter)
  • Installing and configuring plugins for diagnostics, linting and fixing (e.g. lsp-zero)

Life-Changing Moment

But then I stumbled accross AstroNvim, and this changed everything. It’s a Neovim configuration that works right out of the box and can be easily customized as needed.

Prerequisites

Of course, Neovim must be installed first. If you have not already done so, here is an example of its installation:

# Install prerequisites for Neovim
sudo apt-get install -y  \
  git                    \
  make                   \
  cmake                  \
  pkg-config             \
  libtool                \
  libtool-bin            \
  gcc                    \
  g++                    \
  ninja-build            \
  unzip                  \
  curl                   \
  gettext                \
  python3                \
  python3-pip

# Install prerequisites for Neovim plugins
sudo apt-get install -y  \
  fonts-powerline        \
  clangd                 \
  clang-format           \
  ripgrep                \
  gdu

sudo pip3 install        \
  autopep8               \
  cmakelang              \
  cmake-language-server  \
  shfmt-py               \
  pyaml

sudo npm install -g      \
  prettier               \
  tree-sitter-cli

cd /tmp \
  && LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') \
  && curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" \
  && tar xf lazygit.tar.gz lazygit \
  && install lazygit /usr/local/bin

# Build and install Neovim from scratch
cd /tmp \
  && git clone https://github.com/neovim/neovim \
  && cd ./neovim \
  && git checkout stable \
  && make CMAKE_BUILD_TYPE=Release \
  && make install
rm -rf /tmp/neovim

If you are interested in installing Neovim in a Docker container, check out this Dockerfile.

Start the 5-minute Timer

Now that everything is prepared, let’s start the timer and see how long we need to configure Neovim. First we need to get AstroNvim. This can be done like this:

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

After cloning the repository, open Neovim and run “:Lazy sync”

If you are in headless mode (perhaps because you are building a Docker container), you can set up AstroNvim with this command:

nvim --headless -c "autocmd User LazySync quitall" -c "Lazy sync"

Now AstroNvim is basically set up. It has status lines, a file tree, integrated SCM and whatever the developer’s heart desires. But hey, didn’t I mention some customization? Yes, I did. And to get started, we just need to create a new git repository based on this template.

After the repository has been created, it can be integrated similar to the AstroNvim repository:

git clone https://github.com/guenterfischer/astronvim.git ~/.config/nvim/lua/user

nvim --headless -c "autocmd User LazySync quitall" -c "Lazy sync"

From here, you are completely free to create your own custom configuration. But there is one last feature that makes the setup easier. And that’s the community plugin configuration specifications, or astrocommunity for short.

You can easily integrate them into your personal AstroNvim user configuration at astronvim/plugins/community.lua and get a complete configuration for given languages.

Here is an example of my community script:

-- astronvim/plugins/community.lua

return {
  -- Add the community repository of plugin specifications
  "AstroNvim/astrocommunity",
  -- example of imporing a plugin, comment out to use it or add your own
  -- available plugins can be found at https://github.com/AstroNvim/astrocommunity

  { import = "astrocommunity.pack.bash" },
  { import = "astrocommunity.pack.cmake" },
  { import = "astrocommunity.pack.cpp" },
  { import = "astrocommunity.pack.json" },
  { import = "astrocommunity.pack.markdown" },
  { import = "astrocommunity.pack.python" },
  { import = "astrocommunity.pack.typescript" },
}

It’s really just one line to configure diagnostics, linters, fixers, formatters, etc. for a language. It couldn’t be easier!

And that’s it! Of course it’s possible to spend some more minutes or even hours on further configuration (e.g. spending days to find the perfect colorscheme :-)). But with just these steps, Neovim is already transformed into a fully functional IDE.

Neovim
Vim
Linux
Text Editor
Software Development
Recommended from ReadMedium