After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.
VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.
Just type :e ~/. vimrc to vim, type in the line and save (:w).
Press 1 to highlight the current visually selected text, or the current word (if nothing is selected). Highlight group hl1 is used. Press 2 for highlight hl2 , 3 for highlight hl3 , etc. Press 0 to remove all highlights from the current visually selected text, or the current word.
:set syntax=html
You can also put this into your .vimrc:
au BufReadPost *.ezt set syntax=html
Take a look at this Vim wikia topic. Some useful tips:
As other answers have mentioned, you can use the vim set command to set syntax. :set syntax=<type>
where <type>
is something like perl
, html
, php
, etc.
There is another mechanism that can be used to control syntax highlighting called filetype
, or ft
for short. Similar to syntax, you give it a type like this: :set filetype=html
. Other filetypes are perl
, php
, etc.
Sometimes vim "forgets" what syntax to use, especially if you're mixing things like php and html together. Use the keyboard shortcut Ctrl+L (<C-L>
) to get vim to refresh the highlighting.
Note that :set syntax=xml
highlights properly but seems to fail when one is attempting to autoindent the file (i.e. running gg=G
).
When I switched to :set filetype=xml
, the highlighting worked properly and the file indented properly.
To make it automatic, add this line to your ~/.vimrc
:
autocmd BufNewFile,BufRead *.ezt set filetype=html
If you want to just do it for the current file, then type:
:set filetype=html
You could also substitute syntax
instead of filetype
, but filetype
affects more things than syntax
(including syntax highlighting, indenting rules, and plugins), so generally you should use filetype
unless you only want to affect syntax
.
In a .php file (or a html file), you could use a Vim Modeline to force certain commands or settings:
1 /* vim: syntax=javascript
2 *
3 * .submit_norefresh()
~
~
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