Bash_Profile & Bashrc: How To Use Vim Commands To Edit Files & Set Path Variables

Follow Us on Social Media

How To Use Vim Commands To Edit Files & Set Path Variables In .Bash_Profile & .Bashrc

Bash_Profile & Bashrc: How To Use Vim Commands To Edit Files & Set Path Variables


.Bash_profile & .Bashrc are shell configuration files. Whatever you put in these files are automatically loaded when the shell is started. That is why it is particularly important to set your PATH variable within these configuration files to avoid needing to set them up every time you start a new session.

Setting up the path variable in .bash_profile and .bashrc is practically easy.

Check this post to know the difference between .bash_profile and .bashrc.

Vim is a text editor much like your notepad, but a more advanced and sophisticated one.

This text editor is used by programmers a lot for writing codes due to various advantages such as syntax highlighting amongst others.


Vim also has commands that you can execute directly from the terminal. This is something that makes it practically very important as you don't need to navigate the GUI while writing code.


To set path variables in bash_profile and and bashrc, you'll need to make use of common vim commands.

After creating the .bas_profile & .bashrc, next step is to edit them and add configuration scripts. Here, you can add shell configuration scripts.

Open either of the files to edit using: vim file_name e.g., vim .bash_profile

To make imputs i.e., change vim from the command interface to the input interface, press letter 'i'.

Now make your changes and write your codes.

To add a path variable, add the following line:

export PATH/usr/lib/postgresql/14.3/bin/:$PATH

This command is for adding the postgreSQL path to the bash_profile or bashrc.

If you wish to add a path to another application, replace the above path with that of the application path you wish to add.

If you are adding a Postgresql path with a version lower or higher than the one above, change the 14.3 to the version of PostgreSQL you have.

To view the version of your PostgreSQL, in your terminal, enter $postgres -V

This will print out the version of your PostgresSQL.

After editing the bash_profile or bashrc, press escape on your keyboard to return to the command mode of vim.

Now, type :wq


This will save and quit vim.

To make your terminal session grab the latest profile changes, enter source ~/.bash_profile OR source ~ /.bashrc





No comments



Powered by Blogger.