I have been using my school's tux for a while. It was built with nice color code for each syntax for each programming languages. I want to do the same on the machine that I just purchased. When I invoke

vi filename

The view was plain black and white. How do I customize so that when I view the script/code files on terminal, it will have nice color code? For example, if statement will be read, string will be purple, etc. As far as I know, it may have something to do with .profile file?

4 Answers 4


Add the following to your ~/.vimrc:

filetype plugin indent on
set term=builtin_ansi
syntax on

If you’re using iTerm, use this instead of line 2:

set term=xterm-256color
  • 1
    I don't see any vimrc file in my computer. I did ls -a. do I just create one myself?
    – Fyr Zheng
    Commented Aug 17, 2017 at 14:14
  • 2
    @Fyr Yes, you'll need to create one if you've never needed one before. It will be read automatically when it exists.
    – grg
    Commented Aug 17, 2017 at 14:19
  • Thank you, it worked. How can I customize specific color?
    – Fyr Zheng
    Commented Aug 17, 2017 at 14:31
  • Also, after add these three lines. After I enter these 3 lines, when I exit from a file, the file is still remained on the screen. How do I get rid of that?
    – Fyr Zheng
    Commented Aug 17, 2017 at 14:35

Use :syn on to turn on syntax highlighting. Put this in your ~/.vimrc file to use it every time. (Vim should detect your terminal type automatically, no need to worry about that.)

To customize the colors, use the :highlight command. Type :help :hi in Vim for more information on this. For more help on syntax highlighting in general, type :help :syntax-highlighting.

If you want to customize it a lot, you can even create a color scheme. This is basically a list of commands, like a .vimrc file, into which you put all the :hi commands. Make sure to include let colors_name = "whatever" somewhere so it'll work correctly.


Add the following codes in ~/.vimrc

syntax on
colorscheme desert

After this, the file will not remain on the screen or will not create any scrolling problem. All the available colors can be found in /usr/share/vim/vim82/colors


If you want to change the color scheme displayed by vim, you can do as follows:

  1. You can find installed color schemes in the following path: /usr/share/vim/vim*/colors/

  2. To use XXX color scheme type the following in vim text editor: :colorscheme XXX (here XXX is the name of a color scheme as listed in the step 1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .