Enable Vim Syntax Highlighting By Default

房东的猫 提交于 2019-11-28 03:44:00

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

syntax on

EDIT

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

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

The location of the runtime directory varies between operating systems:

  • On my system (Arch Linux, and Mac, thanks @totophe), it's in /usr/share/vim/vim73.
  • On Windows, it's in \Program Files\Vim\vim73.

Also, to highlight Specific TYPE of syntax (or programming language) in a file, you can use following commands, while file is already opened in Vim:

:set filetype=php

OR shortcut:

:se ft=php

Above commands will change the syntax-highlighting of current file as if highlighting PHP Code.

Uncommenting the "syntax on" in vimrc file.

Move to the directory,

cd /etc/vim/

vim vimrc

now search "syntax" and uncomment it. Save it and reopen the file in vim.

For anyone that gets here because of TurnKeyLinux using vim-tiny which doesn't have the syntax module enabled 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

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

To find it, you can type command vimtutor 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 an initial vimrc file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!