Enabling vi syntax colors and highlighting


Browse by products and services

  • Applies to: Grid
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi
  • Applies to: All DV
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi

Last modified: March 10, 2020

Overview

The following guide will show you how to enable syntax colors for VI/VIM.

Instructions

Enabling syntax color scheme

  1. Connecting via SSH to your server
  2. Connecting via SSH to your server
  3. Browse to your user directory with the following command:
    cd ~
  4. Create a .vimrc file with the following command:
    vi .vimrc
  5. Press the "i" key to enter insert mode.
  6. Type the following command below to enable syntax and give a specific colorscheme. This example uses the desert colorscheme:
    syntax on
    
    colorscheme desert
  7. Hold Shift and hit : then type wq to save and quit the file.
  8. You should now be able to use vi and the colorscheme you choose to edit files.

How to text syntax highligiting

To test that syntax highlighting is enabled, simply open a file using vim.

colors.png

How to turn off/on syntax highlighting

While having a file opened through vim, hold shift, then enter the following command:

:syntax off

off.png

:syntax on

on.png

Additional color schemes

  1. You can view additional color schemes by staying connected to your server through SSH and running the following command:
    ls -l /usr/share/vim/vim*/colors/
  2. The output should look similar to the following:

    colors.png

Additional color schemes

The following is a few color schemes installed on the Grid:

  • default
    default_colorscheme
  • elflord
    elflord_colorscheme
  • torte
    torte_colorscheme
  • delek
    delek_colorscheme
  • evening
    evening_colorscheme
  • pablo
    pablo_colorscheme

The rest of the colorschemes installed are as follows: morning, peachpuff, blue, murphy, ron, zellner, darkblue, desert, koehler, and shine.

Can I install my own colorscheme?

Yes, first connect to your server via SSH and type the following:

cd ~ 

Next, you need to create a .vim/colors directory with the following command:

mkdir .vim .vim/colors 

Next, you can upload your own colorscheme into the colors folder you created. Finally, just follow the steps from earlier to set it as your default colorscheme.

TIP:

  • You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. 
  • For more color schemes, you can browse this library on the vim website.
  • You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi. 
  • For more information about vi, please visit: Understanding basic vi (visual editor).