How to Enable the Status Line with Lualine in Neovim/Nvim

Status Line in Neovim provides useful information about the Neovim mode and the file being edited. By default, Neovim displays a simple status line that provides the filename of the editing file. However, the status line can be customized to display important information such as the mode of operation of Neovim, filename, operating system, filetype, position of the cursor line, and more. This can be achieved through a plugin. One such plugin is Lualine, which provides all the necessary information and seamless integration with major themes, making it the best status line plugin.

In this blog post, I’ll show you how to install the Lualine plugin and configure it to work with your current colorscheme.

Prerequisites

Before proceeding with the installation and usage of Lualine in Neovim, make sure you have the following packages installed on your system:

Packer

Packer is a plugin manager for Neovim, and since Lualine is a Neovim plugin, you need to have Packer installed. If you haven’t installed Packer in Neovim yet, you can refer to the guide on installing Packer in Neovim before installing Lualine.

Nerd Font

Nerd Font is used to display icons in the status line, making it visually appealing. There are many nerd fonts available, and you can choose any of them.

If you don’t have any nerd font installed, you can follow these steps to install one. Open the terminal and enter the following command to download Anonymous Pro Nerd Font:

curl -L https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/AnonymousPro.zip > AnonymousPro.zip

After downloading the Anonymous Pro Nerd Font, use the following command to install the fonts on your system:

sudo unzip AnonymousPro.zip -d /usr/share/fonts/AnonymousPro

Finally, reboot your system to apply the font changes.

Installing Neovim Lualine

Installing Neovim Lualine is a straightforward process that involves a few steps. To begin, open the plugins.lua file in your Neovim configuration. If you have followed our guide on installing Packer, your file structure should look like this:

~/.config/
└── nvim
    ├── init.lua
    └── lua
        ├── plugins.lua
        ├── .....
        ├── .....
        └── other configuration files

Now, to install the Lualine plugin, open the plugins.lua file with the following command:

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

If your plugins file has a different name or is located in a different directory, open the file accordingly. After opening the plugins file, add the following two lines to install Lualine:

-- status line
use("nvim-lualine/lualine.nvim")
use("nvim-tree/nvim-web-devicons")
  • lualine.nvim: Lualine status plugin
  • nvim-web-devicons: (optional) This plugin allows Lualine to use icons in the status line.

After adding these lines to the plugins.lua file, save it using the :w command to install the plugins.

Once the plugins are installed, open the init.lua file with the following command:

nvim ~/.config/nvim/init.lua

Then, add the following lines at the bottom of your init.lua file:

-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true

-- empty setup using defaults
require('lualine').setup()

Save and exit the Neovim editor to finish installing the Nvim Tree plugins for Neovim.

Configuring Neovim Lualine

By default, Lualine is well-integrated with popular colorschemes, and you don’t need to configure it manually. You can see the list of Lualine supported themes. With the setting of supported themes, the corresponding Lualine themes will be automatically activated.

In case the corresponding Lualine themes don’t activate in any situation, you can activate the theme by specifying it in the Lua configuration.

To configure Lualine, first, create a Lua configuration file named lualine.lua:

nvim ~/.config/nvim/lua/lualine.lua

Then add the following configuration depending on your level of customization:

Activating Theme

To use a different Lualine theme other than your current colorscheme, add the following configuration:

local lualine_gruvbox = require'lualine.themes.gruvbox'

require('lualine').setup {
  options = { theme  = lualine_gruvbox },
  ...
}
lualine-gruvbox

Changing the Color of Status Line

If you don’t like the default color, you can change it to your desired color. For example, if you want to change the color of the nightfly theme, you can use the following configuration file:

-- import Lualine plugin safely
local status, lualine = pcall(require, "lualine")
if not status then
  return
end

-- get Lualine nightfly theme
local lualine_nightfly = require("lualine.themes.nightfly")

-- new colors for theme
local new_colors = {
  blue = "#65D1FF",
  green = "#3EFFDC",
  violet = "#FF61EF",
  yellow = "#FFDA7B",
  black = "#000000",
}

-- change nightlfy theme colors
lualine_nightfly.normal.a.bg = new_colors.blue
lualine_nightfly.insert.a.bg = new_colors.green
lualine_nightfly.visual.a.bg = new_colors.violet
lualine_nightfly.command = {
  a = {
    gui = "bold",
    bg = new_colors.yellow,
    fg = new_colors.black, -- black
  },
}

-- configure Lualine with modified theme
lualine.setup({
  options = {
    theme = lualine_nightfly,
  },
})

Credit: dev-environment-files

lualine nightfly

Adding Lualine to Init.lua

To activate the following setting, open the init.lua configuration file:

nvim ~/.config/nvim/init.lua

Then add the following line to the configuration file:

require('lualine')

???? If you previously added require('lualine').setup(), replace it with require('lualine').

Conclusion

Lualine is a powerful Neovim plugin that provides useful information about the file and the system. Further customization allows you to personalize your status line to suit your preferences. In this blog post, I have covered how to install Lualine and its dependencies. I have also shown you how to customize the Lualine plugins.

Share your love

Newsletter Updates

Stay updated with our latest guides and tutorials about Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *