In my .vimrc file I use:
syntax on
Today, I was perusing through some .vimrc files from other developers and i've notice a few using:
syntax enabled
Is there a difference? Are these both accomplishing the same goal just using different locution?
To enable Syntax Highlighting feature in VI editor, open the file called /etc/profile. Add the alias function to VI by pointing to VIM in /etc/profile file. This file is used to set alias functions globally. If you would like to set user specific aliases and functions, then you need to open the file .
Vim's scripting language, known as Vimscript, is a typical dynamic imperative language and offers most of the usual language features: variables, expressions, control structures, built-in functions, user-defined functions, first-class strings, high-level data structures (lists and dictionaries), terminal and file I/O, ...
For syntax on
vs syntax enable
, the help files claim:
The ":syntax enable" command will keep your current color settings. This allows using ":highlight" commands to set your preferred colors before or after using this command. If you want Vim to overrule your settings with the defaults, use: > :syntax on
The behavior I see in Vim does not appear to match the above help statement.
After testing locally with some empty .vimrc
s and experimenting with on
, enable
, and placement of highlight commands, I can't figure out what Vim is actually doing (I tested with highlight ColorColumn guibg=#331111
and set colorcolumn=80
). Highlighting is sometimes overwritten and sometimes not.
I no longer trust Vim, so I only let syntax get set once, ever. Here's what I have in my .vimrc
:
if !exists("g:syntax_on") syntax enable endif
I use enable
because of the above claim that it won't overwrite your settings, however it doesn't seem to make any difference when starting Vim.
You can see that h g:syntax_on
shows that on
and enable
source the same file:
Details: The ":syntax" commands are implemented by sourcing a file. To see exactly how this works, look in the file: command file ~ :syntax enable $VIMRUNTIME/syntax/syntax.vim :syntax on $VIMRUNTIME/syntax/syntax.vim
If you're curious, g:syntax_on
gets set in $VIMRUNTIME/syntax/synload.vim
Also running Vim with no plugins/settings vim -u NONE
does NOT load any of the syntax files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With