Highlight word or line in Gvim - vim

I want to mark some words in "Gvim" by color and can't find in "Gvim" manual how to do it.
How can I highlight word/line in "gvim" when I standing on it?

You can use the :highlight and :match commands. For e.g., if you want to highlight a word deadline then do the following:
:highlight DeadlineGroup guifg=#f234f1
:match DeadlineGroup /Deadline/
The first command (:highlight) will create a highlight-group (:help highlight-groups) and the second (:match) will map a regex with that highlight-group.

Related

vim highlight all lines that have marks

There are plugins that show marks, e.g. vim-signature and ShowMarks, but they only show signs at sidebar.
Is there a way to highlight all lines that have marks?
Currently I'm using an expression to do this, for example:
:highlight currawong ctermbg=darkred guibg=darkred
:match currawong /\%12l\|\%34l\|\%5l/
This highlights line 12, 34 and 5.
It's working, but not very convenience.
Please use this command:
:highlight currawong ctermbg=darkred guibg=darkred
:match currawong /\v.*(%'a|%'b|%'c|%'d).*/
:nmap <F5> :redraw!<CR>
It will highlight lines which contains marks: a-d.
Type F5 to force a redraw.

VIM: Underline enclosing parentheses

I know i can highlight matching parentheses in VIM.
Is there a way to underline enclosing parentheses like Sublime does?
Only the 2 parentheses around the cursor without having the cursor on one of them. Example:
Assuming the default plugin for highlighting matching parentheses is enabled, then it should be as simple as adding a few styles to the MatchParen highlight group:
highlight MatchParen term=underline cterm=underline gui=underline
More help on the highlight command:
:help :highlight
Highlights the pair surrounding the current cursor position.
https://github.com/Yggdroot/hiPairs
These plugins highlight the pair of parentheses surrounding your current cursor position:
https://github.com/justinmk/vim-matchparenalways
https://github.com/Yggdroot/hiPairs
ShowPairs

Custom syntax highlighting on current buffer in vim

From time to time I would like to apply some custom extra syntax highlighting on the current buffer.
How can this be done using the build in vim syntax/highlight system (I do not want to use the Highlight plugin)
As example, I would like to highlight all assert statements in current buffer.
If the highlighting is for certain filetypes (e.g. Java) only, and you want it all the time, I'd extend the original syntax with :syn match ... definitions placed in ~/.vim/after/syntax/java.vim.
For spontaneous highlighting, use :match (or :2match), as dwalter has shown.
If you're gonna write a more elaborate mapping, maybe with toggling on/off logic, use matchadd() / matchdelete().
Finally, if you need highlighting for arbitrary words / strings, like marking up a document with a text marker, I'd suggest the comfort of a plugin like Mark (which I have taken over maintaining).
You can use match and highlight if you want.
example:
:hi MyAsserts term=bold ctermbg=Cyan
:match MyAsserts /assert(.*)/
to highlight your assert() statements with Cyan background.
:match without any arguments will reset it.
for more information on either highlight or match look at the documentation via
:help hi or :help match
To reuse your highlighting you can save those commands in a file and use :source file.vim to load it anytime you want. Another way would be to define a command inside your .vimrc.
hi MyAsserts ctermbg=Cyan
command -bar -nargs=0 HiAsserts match MyAsserts /assert(.*)/
"highlight any given regex
command -bar -nargs=1 HiIt match MyAsserts /<args>/
and call it with :HiAsserts to highlight your assert() statements or :HiIt foo to highlight every foo in your buffer.

ignore new lines in vimdiff output

I know that I can ignore white space in vimdiff by se diffopt+=iwhte
but I also want to ignore newline character in vimdiff. How can I do it?
e.g.
if (a>b){
bar()`
would not be shown diff with
if(a>b){bar()
Thanks,
To really omit the added lines, you will have to write a custom diff function, cp. :help diff-diffexpr.
If you just don't want to see the added lines (because they're too visually distracting), you can modify the DiffAdd highlight group to show white-on-white (or black-on-black in the console) text (or any other low-contrast coloring, in a similar way:
:highlight DiffAdd ctermfg=black ctermbg=NONE guifg=bg guibg=NONE

CursorLine highlight in ViM, highlight only line number and spaces/tabs on beginning /end of the line

I use ViM's :highlight CursorLine to change bg color on the current line. But sometimes the text not readable.
I would like a highlight that could only change the background color for the whole line except the text (counting the spaces/tabs in between chars as text).
Is it doable? If yes, how?
As for as I know, there might be no direct support of setting how the cursorline is highlighted.
But, I've got a trick for doing what you want. That is, after we highlight the cursorline, we can change the color settings of heading/trailing spaces in a line as current "background" and "foreground".
:match NoHighLight /^\s\+|\s\+$/
:highlight NoHighLight guibg=background guifg=foreground
A obvious drawback is the part from "the end of the line" to "the boundary of the vim window" will still be painted as the color of cursorline's setting. If it is ugly for you, you can just change the highlight setting of cursorline by only setting its guifg, like:
:highlight CursorLine guifg=red guibg=background
Maybe there are other neat solutions existed, but that is what I can come up with now. :)
Hope that helps a bit.
I have found a solution -
With regard to #Zhaojun's answer: it's not what I wanted (also /^\s\+|\s\+$/ doesn't do much, maybe it should be /^\s\+\|\s\+$/)
The solution I found is (just example color for elflord color scheme)
:highlight CursorLine gui=none guibg=grey10
:set CursorLine
:highlight NoHighLight guibg=background
:match NoHighLight /\S\+\(\s\+\|$\)/
it's however not working well for trailing spaces at he end of line, but I usually delete them
to make them visible I use the following
:highlight EndSpaces guibg=green
:match EndSpaces /\s\+$/

Resources