Vim line between code and line number - vim

This may seem like a simple question but I've probably spent hours looking for this to no avail. How do I create a colored line on the right of line numbers in Vim? Like this:

Not sure about the line, but you can change the foreground color to add some contrast.
From http://vim.wikia.com/wiki/Display_line_numbers:
You can change the color used for the line numbers. For example:
:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE

You would need to change the Vim source code for that. Such a patch is unlikely to be included in Vim, though, because one of Vim's design principles is that its features should be available on all platforms, and anything that doesn't fit into the character raster cannot be implemented in the console. (And even workarounds would require special Unicode characters to emulate such a line.)
Unfortunately, you cannot hack something like this with built-in features: Both sign column and fold column are displayed to the left of the number column. Is that visual distinction really so important for you?!

Unfortunatrly you can't add a line there: there's no option for that and, I believe, no hack.

Related

Render boundary space in Vim (just like VSCode)

I am pretty noob at Vim still, pardon my ignorance
"Boundary" whitespace is any whitespace except single spaces between words, paraphrasing from VSCode docs:
I want to mimic this same behavior in Vim (ideally with no plugins).
An example of how this feature looks in VSCode:
There aren't many resources that I found on this topic. There is Render space if it have multi space in Vim, which addresses this exact same feature (previous example image shown is from that question), but the provided solution does not work exactly as expected.
This is an example of how boundary whitespaces look after trying out that stackoverflow solution:
While the '·' character is shown when there are 2 or more spaces in a row, which is desired, they are also shown highlighted, which is not what I expected
Moreover, if I place the cursor on a line that contains consecutive spaces, they disappear (or are highlighted into invisibility, whatever is happening that renders them invisible)
Excuse my newbie comments in my .vimrc; the rest of the file is commented out
This is another example, in VSCode, of the desired behavior:
Am I missing something from that previous question? Is the highlighting of whitespaces normal or a different issue on its own? Thanks in advance!
The feature you are looking for can be enabled with :help 'list' and customized with :help 'listchars':
The result above can be obtained by adding the following lines to your vimrc:
set list
set listchars=eol:↵,lead:·
If your color scheme makes those characters too visible, you can override its NonText and SpecialKey highlight groups (mentioned in :help 'listchars') to make them more bearable. For example:
augroup MyColors
autocmd!
autocmd ColorScheme * hi NonText ctermfg=235 | hi SpecialKey ctermfg=235
augroup END
colorscheme foobar
Note that listchars was more limited at the time the linked question was answered so, while it was more or less valid at the time, it is no longer necessary to use the conceal feature for this.

How do I set up a visual margin in vi when colorcolumn is not supported?

I am working on vim 7.0 and the colorcolumn is not supported.
I am looking for a visual vertical colored margin to manage long lines. Are there any available options to achieve it? I have a mac and colorcolumn works great.
I have found some similar ones but that is not what I want. Below lines added to .vimrc achieves something similar but it does not give me a visual colored margin. It basically points out anything greater than a certain character range.
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/
Ideally this could be achieved with a later version like this
set colorcolumn=79
This screenshot shows what I am looking for.
With the :highlight trick you included and that romainl linked to, you can highlight the character(s) that are longer than desired, but that won't get you a continuous line (shorter lines will interrupt), only 'colorcolumn' can achieve that.
The only other clumsy workaround I can think of is setting the window width to your desired width, so you notice overlong lines when the window starts scrolling horizontally.
Vim 7.0 is from 2006; you're missing out on much more; I really hope you can upgrade, that's the real solution.

Vim - Force extra spacing between lines for underlining

While using Vim for most of my coding, I typically prefer to have the current line under-lined so it's easier to see where I am in my code. I avoid using things like line-highlighting because it usually makes things harder to see with my bright-text-on-dark-background theme (ie: 'torte' colorscheme).
Here is part of my Vim colorscheme:
hi CursorLine guibg=#0F2130 ctermbg=NONE cterm=underline
hi CursorColumn guibg=#0F2130 ctermbg=darkgray cterm=NONE
I then enable these features in my .vimrc file (ie: ~/.vimrc).
So, in my case, the current line has a colored underline which is the inverted color of the character above it, while the current column has a dark-grey background, while all other text just has a black background.
The only problem I am having here is that I cannot see underscore ('_') characters while coding because the underline for the current line is the exact same color and thickness as the underscore characters. The only workaround, if its even possible, that would make sense here is to:
Increase the spacing between lines
Make the underline appear a few pixels further below my text
Is anything like this possible in Vim (not gVIM)?
Thank you.
If you are using gVim:
:hi! def link CursorLine SpellBad
It will use curl-underline.
Changing the linespace to 10+ will display _ above the Cursorline:
:set linespace=10
#kev: +1; It works in gVIM
However, it seems this just can't happen in Vim, as other commenters have noted.
In the end, I just set the background to be dark grey (ie: ctermbg=253), and then set the cursorline to be darker (ie: ctermbg=black cterm=NONE).
From there, I updated my BASHRC file to contain the following:
export TERM=xterm-256color
This, of all luck, ends up looking better than my previous colorscheme. I now have a modified version of the standard "slate" color scheme with a very dark gray background (ie: ctermbg=253) while the current line has a solid black background.

Vim syntax highlighting hide characters

I'd like to implement a syntax file for vim that hides certain characters in the file. Specifically, I want to write an improved highlighter for reading Markdown files that doesn't display some of the formatting characters, preferring instead to indicate them implicitly. For example, I'd like to have things like *bold* render as simply bold with bold text, or to have headings like
My Header
=========
not show their underline, but just appear a different color. I haven't managed to find any examples so far of vim syntax files that hide specific characters from display. Is this something that is possible in vim? If so, how?
To hide syntax items - or just certain characters - the conceal or Ignore arguments can be used. See
:help hl-Ignore
:help syn-conceal
For an example see the syntax file "help.vim" which is part of crefvim. CRefVim is a C-reference manual which is embedded in the Vim help system. The "help.vim" syntax file extends the standard syntax highlighting for help files.
An example. The '$' character is used here to show text in italic:
Maybe this example is a good starting point for you to dig further...
Habi
You could make your own syntaxfile with an according colortheme, using "bold", "italics" and the like. It wouldn't hide anything, so that your syntax must work with the original text.
For example this could be your syntax for headers
In your syntax you would need:
syn match Header '^\s*\u*\.\s.*$' contains=ALL
hi link Header ModeMsg
and in the colortheme
hi ModeMsg gui=bold guifg=NONE guibg=NONE cterm=bold ctermfg=NONE ctermbg=NONE term=bold
then a header like this
1. This is my new header, being bold
would be shown bold, without any markup at all. By the way, you can export it with the TOhtml feature while keeping the highlighting.

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

Resources