how to highlight strings that begin with sql_
and are inside quotes?
My Logfile:
MGPostgreSQLConnection.OpenQuery; "sql_p_factory_history"-ExecTime: 47ms
2010-11-12T17:28:18+01:00;custom; MGPostgreSQLConnection.OpenQuery; "sql_p_factory_history"-ExecTime+FetchTime: 47ms
2010-11-12T17:28:18+01:00;custom; MGPostgreSQLConnection.OpenQuery; "sql_factory"-ExecTime: 47ms
2010-11-12T17:28:18+01:00;custom; MGPostgreSQLConnection.OpenQuery; "sql_factory_contactperson"-ExecTime+FetchTime: 62ms
My vimrc (This doesn't work, of course):
au BufRead,BufNewFile *.log syn match "sql_*"
au BufRead,BufNewFile *.log hi sql guifg=white guibg=red
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.
You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.
You were nearly there! This version (works and) doesn't highlight the quotation marks.
au BufRead,BufNewFile *.log hi sql guifg=white guibg=red ctermfg=white ctermbg=red
au BufRead,BufNewFile *.log syn match sql /"\zssql_\w*\ze"/
See the following for more information:
:help :syn-match
" for syntax matching, erm, syntax:help /\zs
" sets the start of the match there:help /\ze
" sets the end of the match there:help /\w
" word characterDebugging:
The command :verbose :syn
should give you something like this:
--- Syntax items ---
[...]
sql xxx match /"\zssql_\w*\ze"/
And :verbose :hi
:
Last set from ~/.vimrc
[...]
sql xxx cterm=bold ctermfg=7 ctermbg=1 guifg=white guibg=red
The xxx
should be in the same colours as you have specified (and look like the highlighting in my screen-shot). If you don't see those, check that your .vimrc
(or _vimrc
on Windows) is sourced:
:scriptnames
1: /home/javh/.vimrc
[...]
Of course this only works when:
:echo has('syntax')
...returns 1
(or :version
includes +syntax
).
The syntax for syn match
is syn match highlight_group reg_exp
.
So, try :
au BufRead,BufNewFile *.log syn match Todo /"sql_\w\+"/
Why don't you read the help for :syn
? Vim help is so good that you find all answers fast :)
:help :syntax
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