• Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About Us
    • About CSEStack:
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • Campus Ambassador
  • LeaderBoard
CSEstack

What do you want to Learn Today?

  • Programming
    • C/C++
    • Python
    • Java
    • HTML CSS
    • SQL
  • CSE Subject
    • Compiler Design
    • Computer Network
    • COA
    • Data Structure
    • DBMS
    • Operating System
    • Theory of Automata
    • Web Technology
  • Linux
  • Trend
    • Artificial Intelligence (AI)
    • Big Data
    • Cloud Computing
    • Machine Learning (ML)
  • GATE CSE 2020
    • Self Study Plan
    • Complete Syllabus
    • FREE Test Series
    • Topper Interview (AIR 15)
    • Recommended Books by Topper
  • Career
    • Placement Interview
    • Jobs
    • Aptitude
    • Quiz
  • Material
    • Recommended Books
    • Software Installation
  • Contribute to Us
    • Write for Us
    • Submit Source Code or Program
    • Share Interview Experience
  • Tools

Set Up Vi/Vim editor by Highlighting Syntax for Programming in Linux

Aniruddha Chaudhari/13 Jan, 18/3645/0
Linux

When does someone ask me what platform to choose to get excel in programming?
“Linux”. No doubt.

And the best editor?
“Vi/Vim” on Linux systems.

In this tutorial, I will show you how to set highlight syntax in VI editor for programming in your Linux systems. At the end of this post, you will get a clear idea, why and how you should start using Vim editor to get excel in coding.

Table of Content:

  • How is Vim different from Vi for Programming?
    • Syntax Highlighting
    • Why Programmer should use Vim
  • Installing Vim on Linux System
  • Set Vim as default vi editor
  • Enabling/Disabling Syntax Highlighting in Linux

 

Before digging into this tutorial, if you are programme you should know the functionality difference between vi and vim editor.

How is Vim different from Vi editor?

Vi is very popular, simple black and white editor in Linux. If you look at the modern editor, Vi lacks on a certain thing. One of such a thing is Syntax Highlighting. Vi editor does not support syntax highlighting. Many of the programmer reports- vi syntax highlighting not working.

Syntax highlighting is one of the primary features to have for any editor. It makes your code more colorful by highlighting specific color as per the context and meaning of a particular line of code. The syntactical text will be shown with some specific color.

Ex. String message will be shown in Red Colour, code comments in blue, programming keywords with green color…

Why should you use Vim over Vi?

Vim is advance to the VI editor. Vim offers many advanced features over Vi including Syntax highlighting. (I will not be discussing other differences as it is not the scope of this article. I will try to cover those difference in my upcoming article.)

When you look at the highlighting code, it looks more readable. And it sparks immediately what kind of data it is. You can find the glimpse of context behind the line of code.

Vim supports syntax for many of the popular programming languages like Python, C/++, Java… and many other advanced programming languages.

vim editor Linux

If you are learning programming languages, you can refer following tutorial links.

  • Python
  • C/C++
  • Java

Vim is the superset of Vi. Basically, whatever feature we have with VI, it comes with Vim editor as well.
So, if you are into programming, move from Vi editor to Vim.

There are certain Linux distributions like Fedora / CentOS / Red Hat (RHEL) doe snot provide enhanced Vim editor. To install on those systems, follow the commands given below.

Note: Other Linux distributions come with preinstalled vim editor. So, you can skip installing vim.

Installing Vim on Fedora / CentOS / Red Hat (RHEL):

Vi editor comes preinstalled on all the Linux distribution including Ubuntu, Redhat… But, it does not highlight syntax. Syntax highlight function is present in Vim editor.

If Vim editor is not installed on your system, you can install it with the following command.

yum -y install vim-enhanced

To run above command you need your Linux system connected to the internet. If you don’t have an internet connection, you can download vim package from any other connected system. And install it on your system.

Vim editor is advance over simple Vi editor.

Many of us are habitat running command Vi in Linux terminal to open any text file or source program. And by default, it opens Vi editor.

Open Vim as Vi editor (By setting alias):

You can open Vim editor by running command vi. You just need to set alias. It is easy doing it in Linux.

To add an alias and to open Vim as vi editor, following the steps those are given below in your Linux.

There are two ways to set alias- globally or only for the specific user in Linux.

Set alias Global (for all the user on Linux system):

Open Linux terminal and run the command.

vi /etc/profile

It will open /etc/profile file. Add a line at the bottom of the file.

alias vi=vim

Save the file.

To make it work, you have to refresh the changes. Run the below command in the terminal.

source /etc/profile

Now all the users on Linux can open Vim editor by running command vi in the terminal.

Set alias for the specific user on Linux system:

Suppose I have logged into the user profile named – csestack.  To add an alias for only specific to the csestack, you need to make the changes in the .bashrc file.

vi /home/csestack/.bashrc

Add below the line of code at the end of the file.

alias vi=vim

Refresh these changes by running below command.

source /home/tecmint/.bashrc

Now check if the if the alias is set properly. Open any file in vi editors by typing command in the terminal.

vi <file_path>

It will open Vim editor instead of Vi.

You can see the text in the syntax highlighted format rather than simple white text.

That’s all.

You can also turn off the syntax highlighting in Vim editor. Reverse engineering works.

I did not find any solid reason to disable the syntax highlighting in Vim editor. (If you get any reason to use Vim without syntax highlighting, let me know in the comment. 😛 )

Still… Here is the way you can turn the syntax highlighting on/off in VIM editor.

Turn On/Off Highlight Syntax in VI Editor for Programming

Open any file in Vim editor

vi <file_path>

As we set an alias for Vi, it will open the file in Vim editor. Text in the file will be highlighted with different color.

Vim Command for “Syntax Off”

Use the command :syntax off in Vi editor.

In below example, I just wrote simple Python program. You can see all the text in white. There will be no syntax highlighted.

disable syntax in Vim

Vim Command for “Syntax On”

Use the command :syntax on in Vi editor. You can see the Python code is highlighted in the editor.

highlight syntax in VI editor for programming

This is all about to highlight syntax in VI editor for programming in Linux. Now, you are ready for your playground. Enjoy the coding.

Related Post: 6 Commands to Edit File in Linux (File Handling with or without Vi editor)

If you find it useful, do share with your friends. And don’t forget to mention why do you love coding in Vi.

In upcoming articles, I will be sharing more vi editor tricks and shortcodes. Stay tuned!

linuxlinux cmdvim

Related Posts

Linux

Step-by-Step Commands to Write Your First Vim Function Example | Rules | Uses

Linux

Vim Case-Insensitive Search in Linux [Step-By-Step Commands]

Linux

7 Linux Hostname Commands with Example | You should Know

Aniruddha Chaudhari
I am complete Python Nut, love Linux and vim as an editor. I hold Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack Portal.

Leave a Reply Cancel reply

Interview Experiences

AccentureAgriChain Akamai Amazon Amdocs American Express Attra Infotech BARC Barclays BlockGrain BYJUS Cisco Cognizant Coupon Dunia Credit Suisse DE Shaw Druva Experis IT Eze Software Factset Fiorano General Electric Incture Technologies Infosys Kasmo Cloud Microsoft MindTree Mu Sigma Numerify Opteamix Oracle Persistent Pole to Win Qualcomm Reliance Riverbed Syntel TCS Tech Mahindra Teradata Terralogic Virtusa Wipro

Interview Questions



You can share your interview experience.

Don’t Miss !

Latest Articles

Cisco Online Test Pattern and Interview Questions for Freshers


[7 Best Tips] How to Make Daily Study Timetable and Stick to It?


Persistent Written Test and Technical Coding Questions [Paper Pattern]


10 Top Website Design Tips for Small Business to Boost Up Your Sales


Main Difference Between remove del and pop in Python List


Tech Mahindra Placement (Online Test | Essay Writing | Interview Questions)


Importance of Career Exploration for High-School Students | Why?


Favorite Topic

AI algorithm array bigdata bit manipulation career Code Computer Network cpp data analytics database data scientist Data Structure db DBMS difference between Django education GATE GATE Topper Interview HTML ibm IBM ISDL interview IP address Java JavaScript Jobs Linked List linux linux cmd nit OOPs Concept os Programming Python python list Qualcomm SOAP sorting stack string vim webbrowser web development

Contribution to Community

  • Contribute to CSEstack Portal
  • Submit Your Source Code or Program
  • Share Your Interview Experience
  • CSEStack Leadership Board
  • Campus Ambassador Program by CSEstack

About CSEstack Portal

  • About CSEStack:
  • Contact Us
  • CSEStack Campus Ambassador
  • Recommended Books by Expert

© 2019 – CSEstack.org. All Rights Reserved.

  • Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About Us
    • About CSEStack:
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • Campus Ambassador
  • LeaderBoard