AstroNvim uses Heirline.nvim for both the custom statusline, tabline, and winbar. Heirline is an extremely minimal statusline plugin that does not come with any preconfigured elements but focuses on speed and extensibility. To build our statusline, we have built a Lua API of elements into AstroUI that we use to build our own statusline. This can in turn be used in your user configuration to customize the statusline, tabline, and winbar.
Basic Options
There are some basic options that we have set up in AstroUI to configure our internal status API. These options are used to easily change things like the colors of sections and the separators used for sections. These would be in a top level status table in your AstroUI plugin configuration options.
status.attributes provides an easy way to override the highlight attributes for each component that we provide in the status API. The available options here can be found with :h attr-list. Similar to the status.colors table, we have set the key values corresponding to the names of the components in require("astroui.status").component Any component can be given attributes.
status.colors provides an easy way to override the color of each component that we provide in the statusline. We have provided the default options for these which are derived from the current theme that is loaded. The values that we show are the highlight group name and the property that they are using. We also set values such as git_branch_fg and treesitter_fg, corresponding to the names of components in require("astroui.status").component. Any component can be given a color here followed by _fg and _bg to control the foreground and background colors. If a value is not provided then it defaults to section_fg and section_bg. We do not use custom colors for the other sections by default which is why only git_branch_fg and treesitter_fg are set.
status.icon_highlights lets you easily control when breadcrumbs and filetype icons should be dynamically or statically colored. By default, LSP breadcrumbs have highlighting disabled and the filetype icon is colored in the statusline, colored for active and visible buffers in the tabline, and disabled in the winbar. These values can either be true or false to enable/disable them always, or a function where the first component is the Heirline component for doing dynamic changing when to color the icon.
status.separators provides an easy way to change the character that surrounds your statusline components. The key is the side of the component and the two characters are the characters to be put on the left and right of the component respectively.
Default Options:
Using astroui.status Module
AstroUI provides a module that can be loaded with require("astroui.status") for building components in Heirline for the statusline, tabline, and winbar. It has several submodules:
Module
Description
astroui.status
Easily import all of the below modules
astroui.status.component
A collection of methods to assist in building entire components. This is the main piece to interact with when building custom statuslines
astroui.status.hl
A collection of methods to assist in setting the color of a component
astroui.status.provider
A collection of methods that can be set as Heirline providers
astroui.status.condition
A collection of methods that can be use as Heirline conditions for controlling when components are enabled
astroui.status.init
A collection of methods that can be set as Heirline init functions for building components with dynamic subcomponents such as LSP breadcrumbs
astroui.status.utils
A collection of miscellaneous helper functions that astroui.status uses such as surrounding components and getting buffers
astroui.status.env
A place to store globally accessible variables such as separators, mode text, etc.
astroui.status.heirline
A collection of tools specific for Heirline as well as a few aliases for easily interfacing with Heirline utilities
Heirline is built through building up components in a nested way, where each component either has itβs own sub components or a provider to tell what content should be displayed. For a detailed description on the basic concepts of configuring Heirline, please check out their extremely well written cookbook.
Building a Component From Scratch
To build a component from the ground up, we can first start by selecting a provider from the require("astroui.status").provider module, for example we can use the require("astroui.status").provider.mode_text provider to get the text for the current mode (i.e. NORMAL, INSERT, etc.). Each provider takes a single argument table with options. Some providers have their own options, but all have a common set of options for stylizing the string they provide. These options include padding, separator characters, and an icon to be used.
Using these options we can start building our component:
This will give us a component where the text will be the current mode displayed as text. But now we want to be able to have the background of the mode to change colors along with the mode. This is where the require("astroui.status").hl module comes into play. There is a method there for getting the highlight for a mode with require("astroui.status").hl.mode. Each of these hl methods are designed to be passed in by name instead of resolving the function to the hl field in a Heirline component. For example, we can add the mode highlighting to our component as such:
This will give us a simple component where the background changes colors with each mode and displays the text of the current mode. If we want to make this component a bit prettier and add surrounding characters, we can use the require("astroui.status").utils.surround function with our component to do this. This surround method also handles setting the highlight group so we no longer need to set that inside of our component. An example of this would be:
This function takes three parameters: the first parameter (left and right side respectively), the second parameter is the function for setting the color for the background of the component and the foreground of the separators, and the third parameter is the component that should be surrounded. In turn it gives us our final component that can be used inside of Heirline.
Using the Predefined Components in require("astroui.status").component
Building components from scratch is a powerful method that gives users complete control, but for the most part itβs nice to have fully built components without having to think as much about whatβs going on internally. For this we have created several out of the box component building functions for things such as the mode, file details, git information, etc. With these, it becomes much easier to build components that you would want in your statusline. For example, to recreate our previous mode text component we can do this:
This will automatically set up the surrounding and colors that we want and defaults to it being a left aligned component. If you are going to place the component on the right side and want it to have the right side separators instead, you can do this:
Default Heirline Configuration
This is a code block that redefines the default statusline and winbar that are used in AstroNvim inside of the user configuration file for reference and a starting point to make modifications:
Default Statusline With Mode Text
Some users want to be able to add the mode text to their statusline easily, AstroUIβs astroui.status lua module as well as Heirline make that very easy to do in their user configuration file.
Heirline plugin specification that adds the mode text to the statusline:
Default Statusline With Clock
Some users want to be able to add a clock to their statusline easily, AstroUIβs astroui.status lua module as well as Heirline make that very easy to do in their user configuration file.
Heirline plugin specification that adds the clock to the statusline:
Replicate NvChad Statusline
NvChad comes with a very specific statusline configuration that a lot of people like, so we figured it would be a nice exercise of the extensibility of our astronvim.utils.status API to show how to build that statusline in AstroNvim. Warning: This is a fairly complicated example and is meant to be used by people who want it and to demonstrate how much you can customize the statusline.
Plugin specification that recreates the NvChad statusline in AstroNvim:
Replicate Visual Studio Code Winbar
Visual Studio Code has a default bar at the top of files that many users may prefer to AstroNvimβs default. Their winbar shows the path to the current file (relative to the working directory) along with the LSP provided breadcrumbs. This is achievable through our status API as well!
Plugin specification that recreates the winbar in Visual Studio Code: