Powerline For VIM and Bash on Ubuntu 22.04

This tutorial intends to teach you to Install Powerline and Configure it for Bash and VIM on Ubuntu 22.04. Powerline is a text-based tool that provides status lines and prompts for bash shell, vim, and many other applications such as zsh, tmux, etc.

You can follow this guide to integrate Powerline with the Vim text editor, and Bash shell on Ubuntu 22.04.

Install Powerline and Configure it for Bash and VIM on Ubuntu 22.04

Before you start your Powerline installation and configuration, you must have access to your server as a non-root user with sudo privileges. This lets you run commands as a superuser in your terminal. For this purpose, you can visit this guide on Initial Server Setup with Ubuntu 22.04.

Then, proceed to the following steps to complete this guide.

Step 1 – Install Powerline on Ubuntu 22.04

Here we use the Univers repository for Ubuntu to install our Powerline. First, run the system update by using the command below:

sudo apt update

Then, add the Universe repository to Ubuntu 22.04 with the command below:

sudo add-apt-repository universe

When you are done, use the following command to install Powerline:

sudo apt install powerline -y

Now proceed to the following steps to configure Powerline for bash and VIM.

Step 2 – Configure Powerline for Bash Shell

At this point, to configure Powerline for the Bash shell, you need to edit the bashrc file. Open the file with your favorite text editor, here we use the vi editor:

sudo vi ~/.bashrc

Add the following Powerline configuration lines to the file:

# Powerline configuration
if [ -f /usr/share/powerline/bindings/bash/powerline.sh ]; then
  powerline-daemon -q
  POWERLINE_BASH_CONTINUATION=1
  POWERLINE_BASH_SELECT=1
  source /usr/share/powerline/bindings/bash/powerline.sh
fi

When you are done, save and close the file.

To apply the changes, run the following command:

sudo source ~/.bashrc

After executing this command, you should see Powerline segments appear in your prompt.

Step 3 – Configure Powerline for Vim

To configure Powerline for the Vim editor, Vim must support Python 3 on Ubuntu 22.04. You can verify this by running the command below:

vim --version

From your output, look for the python3, which must have a plus sign (+) next to it.

Output
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 18 2022 19:26:30)
Included patches: 1-3995
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
...
 +python3 

Then, open your vimrc file by using the command below:

sudo vi ~/.vimrc

Add the following Powerline configuration lines to your file:

python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup

set laststatus=2

The laststatus setting displays the status bar in Vim and makes Powerline visible by default.

When you are done, save and close the file.

For more information about Vim, you can visit the Vim Docs page.

That’s it. You are done.

Conclusion

At this point, you have learned to Install Powerline on Ubuntu 22.04 and configure it for bash shell and Vim by adding some configuration lines to the bashrc and vimrc files.

Hope you enjoy it. You may be interested in these articles:

How To Install Erlang on Ubuntu 22.04

How To Install Monitorix on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!