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.
Related
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.
I want to get Vim (MacVim for now) to highlight non-ASCII characters. As per this answer I added these two lines to my vimrc:
syntax match nonascii "[^\x00-\x7F]"
highlight nonascii guifg=#ffffff guibg=#ff0000
" highlight link nonascii ErrorMsg (this didn't work either)
And I pasted some text containing a right single quote (hex 2019) into an HTML file. Vim didn't highlight it.
But when I replaced the two lines above with the following, it worked:
syn match ErrorMsg /[^\x00-\x7F]/
Why didn't the first version work?
EDIT: further investigation shows neither version works when I open vim with my file. But both work if I execute them by hand when vim is already open.
Your solution only works for the GUI (gvim); if you're using Vim from a terminal, add ctermbg and/or ctermfb, for example:
highlight nonascii guifg=#ffffff guibg=#ff0000 ctermbg=red
I was able to get my second version working by prepending autocmd BufEnter *:
autocmd BufEnter * syn match ErrorMsg /[\x00-\x7F]/
The idea came from this answer about non-filetype-specific syntax highlighting.
I would like to highlight overlong lines in Vim (like here: https://stackoverflow.com/a/235970/1329844) as well as trailing whitespace (like here: https://stackoverflow.com/a/4617156/1329844). However, whenever I use both highlights, only the last one is applied.
I have the following code in my .vimrc:
highlight OverLength ctermbg=0 ctermfg=197
match OverLength /\%>80v.\+/
highlight ExtraWhitespace ctermbg=0
match ExtraWhitespace /\s\+$/
When I open a file, only trailing whitespace is highlighted. If I exchange the order of the two highlight/match pairs, only overlength lines are highlighted. What do I need to change so that both patterns are matched and highlighted?
The :match command can only have one active pattern. If both of your highlights used the same colors, you could combine the patterns with \|. Here, you have to use one of the two alternative commands: either :2match or :3match, or you can use the (newer) matchadd() function, where you can specify arbitrary numbers (> 3) as the (last) {id} argument.
:call matchadd('OverLength', '\%>80v.\+', 10, 4)
:call matchadd('ExtraWhitespace', '\s\+$', 10, 5)
I think, Ingos solution is to be prefered, but nevertheless, you can use this:
:match MyCustomHighlight /\%(\s\+$\)\|\(\%>30v.\+\)/
:highlight MyCustomHighlight ctermbg=0 ctermfg=197
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
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\+$/