3

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?

8

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
  • 1
    @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
3

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.

0

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 .