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?


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
  • I don't see any vimrc file in my computer. I did ls -a. do I just create one myself? – Fyr Zheng Aug 17 '17 at 14:14
  • @Fyr Yes, you'll need to create one if you've never needed one before. It will be read automatically when it exists. – grg Aug 17 '17 at 14:19
  • Thank you, it worked. How can I customize specific color? – Fyr Zheng Aug 17 '17 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 Aug 17 '17 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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.