gvim: Colour lines differently containing TODO/HACK/etc? - vim

Often I'll put comments in code like TODO/HACK/BUG: I'd love if these showed up glaringly when I did a diff of the code in vim.
Is there an easy way to set this up?

You can define a syntax group like this:
:syntax match TODOs ".*TODO.*\|.*BUG.*\|.*HACK.*"
This will match entire lines which contain either TODO, BUG or HACK in them.
Then you can use the highlight command to highlight it.
:highlight TODOs ctermbg=red ctermfg=yellow term=bold,italic
You can add both the lines to your vimrc or the syntax file for appropriate file types.

Related

Highlighting set of specific keywords in gvim

I have tried highlighting specific words by adding them in .vimrc, colorscheme file and also in syntax.vim(I changed one at a time, not altogether).
syn match mygroupwords '\c\<\(-word1\|-word2\)'
hi def link mygroupwords colo_words12
hi colo_words12 guifg=red1 gui=bold guibg=white
But somehow it seems to be getting overwritten by default syntax highlighting
i need to highlight keywords irrespective of color-scheme or file-type which have following words-
Ex; -word1 , -word2
Any suggestions?
explanation of your failed attempts
A colorscheme just provides color definitions for predefined highlight groups; that's the wrong place for actual syntax matches! ~/.vimrc is the first configuration that is read; if a filetype is detected and a corresponding syntax script is loaded, that will override your syntax definition.
syntax extensions
If your desired highlightings are extensions to an existing syntax, you can place :syntax match commands in a syntax script in the after directory. For example, to extend Python syntax, put it in ~/.vim/after/syntax/python.vim. That may still fail if the original syntax obscures the match; sometimes, this can be solved via containedin=...
independent marks
If your highlightings are independent of syntax and filetype, there's a different built-in mechanism: :match (and :2match, and additional variants via :call matchadd(...)):
:match mygroupwords /\c\<\(-word1\|-word2\)/
This goes on top of (and is independent of) syntax highlighting. However, it is local to the current window. So, if you put this into your .vimrc, it will only affect the first window (but any files viewed in there). To apply this globally to window splits and tab pages, you have to use :autocmds. It's not trivial to get this totally right. If you need such a full solution, have a look at my Mark plugin; this supports multiple colors, allows presetting with :[N]Mark /{pattern}/ (similar to :match), and highlights in all windows.

Changing color of vim syntastic error window

I have installed syntastic on VIM to help me show errors in PHP code however with the current colorscheme/setting I have to following colors:
As you can see it's very hard to read, I wonder if there is a way to change the color if this error window specifically.
If this is only for the current selected item in the quickfix window, that's the Search highlight group on top of the normal quickfix highlighting. You then have to change either one; the Search group will affect search results in other windows, too.
If this is other / special Syntastic highlighting, you best look through all groups in the :hi output to find the bad one.
Overriding
Unless you want to completely switch your colorscheme, you can adapt individual highlight groups via :highlight commands after the :colorscheme command in your ~/.vimrc. Either :hi link to another predefined group, or provide your own ctermfg=... guifg=... etc. color definitions, as described by :help highlight-args.
Syntastic doesn't change (nor cares about) highlighting of the error window. It's a plain quickfix window, with filetype qf. Looking at syntax/qf.vim, the default highlighting is this:
syn match qfFileName "^[^|]*" nextgroup=qfSeparator
syn match qfSeparator "|" nextgroup=qfLineNr contained
syn match qfLineNr "[^|]*" contained contains=qfError
syn match qfError "error" contained
hi def link qfFileName Directory
hi def link qfLineNr LineNr
hi def link qfError Error
Thus, if you see the quickfix window in different colours than the main text, it's because your colour scheme has specifically intended it to look that way. You can override highlighting for qfFileName, qfSeparator, qfLineNr, and qfError to make it more readable, but the better solution IMO would be to use a less broken colour scheme.
Edit: Vim 8.0.641 and later has QuickFixLine.

VIM syntax coloring lua function name?

I'm using VIM via terminal (SSH) and want to modify my syntax coloring settings in VIM to make the function_name Yellow for Lua programming. Unfortunately, I can't figure out how to do that.
For example, in the code below - I want my VIM to syntax color myFunc yellow
local function myFunc(arg1)
...
end
I've been able to figure out how to make function yellow, by using this code below:
hi luaFunction ctermfg=Yellow
But this code does not color the word myFunc yellow (and frankly, I'd rather not syntax color function at all)
Question: Any ideas how I can syntax color the function_name in Lua?
Another (more complex) regex to match the function name.
:hi luaCustomFunction ctermfg=yellow
:syn match luaCustomFunction "\(\<function\>\)\#<=\s\+\S\+\s*(\#="
This uses a look-behind to match the word function. Then after 1 or more spaces it will highlight any word that has a parenthesis as the first non whitespace character after it.
This only highlights the function name. It does not highlight the parenthesis.
I think if you put these commands in .vim/after/syntax/lua.vim it should work.
The problem with putting them in your vimrc is that sometime after the vimrc is sourced the syntax highlighting file is sourced and generally the first line in there is syn clear. (Which wipes the custom syntax highlighting you just set)
This very naive implementation works with your sample:
:hi luaCustomFunction ctermfg=yellow
:syn match luaCustomFunction "\s\+\zs\S\+\ze("
It is obviously very limited but at least you get a starting point. Read :h syntax for further help.
How about:
hi def link luaFunction Function
hi Function ctermfg=Yellow

How do I make vim syntax highlight a whole line?

I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $ with a \n^, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5 will highlight 5 fewer characters, but he=he+5 doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
It is possible to highlight an entire
line using the :sign mechanism.
An example can be found at :help
sign-commands
In a nutshell:
:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt
Obviously, you should pick a higlight
group that changes the color of the
background for the linehl argument.
source: Erik Falor, vim mailing list
From the documentation on syn-pattern:
The highlighted area will never be
outside of the matched text.
I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line

How can I make hard-coded strings heinous-looking in VIM?

I was inspired by this (number 2) to make my hard-coded strings ugly.
How can I do this in VIM?
The language-based files are stored in $VIMRUNTIME/syntax, one .vim file per language, so that's where you need to go to change things.
For example, my C file is stored in C:\Program Files\Vim\vim70\syntax\c.vim and, if you add the following line near the end, before the let b:current_syntax = "c", you'll get the exact effect you require:
hi String guifg=#ff0000 guibg=#ffff00
For text-based VIM, the ctermfg and ctermbg options need to be used instead, something like:
hi String ctermfg=Red ctermbg=Yellow
I haven't tested these since I only use gvim nowadays.
In your .vimrc:
highlight String guifg=1 guibg=11
highlight clear String
highlight link String Error
A bit over the top IMO, so you might want to not make it permanent.

Resources