Enable default Vim syntax highlighting

I know how to turn syntax highlighting on and off in vim by running this in the editor:

:syntax on/off 

But I want syntax highlighting to be turned on by default, so I don’t need to turn it on every time I run vim.

How to do it?

+113
vim vim-syntax-highlighting
Jun 30 '12 at 7:59
source share
7 answers

Edit $HOME/.vimrc (Unix / Linux / OSX) or $HOME/_vimrc (Windows) to include the following line:

 syntax on 

EDIT

If syntax highlighting doesn't work when you start Vim, you probably don't have $HOME/.vimrc or $HOME/_vimrc (now known as vimrc ). In this case, you have two options:

  • Create an empty vimrc .
  • Copy vimrc_example.vim as vimrc (recommended, thanks @oyenamit). You can find vimrc_example.vim in the vimrc_example.vim directory.

The location of the runtime directory depends on the operating systems:

  • On my system (Arch Linux and Mac, thanks @totophe), it is located in /usr/share/vim/vim73 .
  • On Windows, this is located in \Program Files\Vim\vim73 .
+171
Jun 30 '12 at 8:00
source share

Also, consider updating the draft syntax highlighting that appears by default in VIM:

Here is what I got, which is much easier on the eyes:

Java syntax highlighting and colors for vim

You will need to copy some files to your /home/yourusername/.vim/colors and /home/yourusername/.vim/syntax . Then configure additional commands in /home/yourusername/.vimrc and you should get what I get.

https://github.com/sentientmachine/erics_vim_syntax_and_color_highlighting

+9
Dec 27 '13 at 5:35
source share

In addition, to highlight a specific type of syntax (or programming language) in a file, you can use the following commands when the file is already open in Vim:

 :set filetype=php 

OR shortcut:

 :se ft=php 

The above commands will change the syntax highlighting of the current file, as if it highlighted the PHP code.

+8
Jan 03 '15 at 22:24
source share

Uncomment the "syntax" in the vimrc file.

Move to the directory

 cd /etc/vim/ vim vimrc 

now look for "syntax" and uncomment it. Save it and open the file in vim again.

+5
May 28 '14 at 11:54
source share

For anyone who gets here because of TurnKeyLinux using vim-tiny that doesn't have a syntax module, try this article to install full vim

http://www.turnkeylinux.org/forum/support/20140108/solved-bash-command-not-found-after-replacing-package

TL; DR

 # apt-get remove vim-tiny # apt-get install vim # hash vim # vim 
+3
Jul 09 '14 at 3:52
source share

I also found that this is one of the lessons in vimtutor .

To find it, you can type the vimtutor command in your terminal (I used on Mac) and scroll down to see if there is a lesson called CREATE A STARTUP SCRIPT (for me it was lesson 7.2), where it describes how to set up the source vimrc file.

+1
May 20 '18 at 17:53
source share

I added syntax on options to my $ HOME / .vimrc (Mac) and it works.

0
Jan 18 '19 at 9:24
source share



All Articles