Cursorline only highlights textwidth not entire window - vim

I like to edit my code in fullscreen and like a visual hint what the textwidth is. I have the text that is passed the 79 characters highlighted using OverLength. I created another visual indicator by setting the ColorColumn to +1. Instead of the ColorColumn, I would prefer if the CursorLine only highlighted the portion of the line is the textwidth rather than the entire line, i.e. CursorLine stops after 79 characters. Is that possible?
Thanks!

CursorLine always covers the entire width of the current window (multiple lines if 'wrap' is set), regardless of the actual length of the line. The length also cannot be influenced by any built-in option. Same applies to CursorColumn in the vertical direction.
The recommended way to highlight a certain text width is via ColorColumn.

Related

How do I set an unlimited textwidth in Vim?

In Vim, I don't want to have a text width at all. I would like lines to go on forever. I tried set textwidth=0 but fq will still wrap the lines up to a certain number. The only way I can do this now is to set textwidth to a very large (but not too large) number. Is there a way to say that I want an unlimited text width?
Setting textwidth to 0 is the right way to not have a limit on the text width. As for gq, it's documented that it uses the screen width if textwidth is set to 0.
If you want to just join lines and not wrap them at all, then you can just use J instead of gq, which will join the lines into one line, and may provide what you're looking for in terms of formatting.

How to get the color of some element in Vim and apply it to another element

This is probably a strange question, but I'm trying to change the current line number in Vim to something different from all other numbers in the line number column.
Thing is, I don't want to change it to a specific value, but to the value of some other gui element.
For instance, change the line number colors to the ones of TabLineSel element:
TabLineSel xxx term=bold ctermfg=2 ctermbg=10 guifg=#859900 guibg=#073642
How can I do this in Vim?
Type
:highlight
in Vim. It will show you all the currently defined group with the color/rendering next to it.
I am not sure which one you want to change but I think you are looking to change either the CursorLineNr (only the number) or the CursorLine (the whole line) group.
To find out in which file it is defined :
:verbose hightlight CursorLineNr
Modify the file, copy paste the line next to TabLineSel and relauch VIm.

Vim colorcolumn interrupted when using wrap

When using set colorcolumn=80 in conjunction with set wrap, the colored vertical column is interrupted, since wrapped lines are still considered as one single line. I think a solution might be to highlight columns 160, 240, ... as well, but I don't know enough Vimscript to implement this.
Please have a look at the following .gif animation to see what I mean:
Is it possible to display the colorcolumn as a continuous vertical bar?
It doesn't appear that vim provides a way of doing this by default. However,
the colorcolumn option allows you to specify more than one column to highlight. (in a comma seperated list) So I think this should do what you want:
set colorcolumn=80,160,240

Limiting text width does not work as expected if not inserting at the end of a line

I know we can use :set tw=80 to limit the text width. However, if we insert text before the end, this function doesn't work at all.
For example, let's say we type "Would you like to have responses to your questions sent to you via email?"
If we continue to input after "?", tw works fine. But if we insert before say "have", it doesn't break off the line even if it exceeds the specified text width.
Is there any way to make this work in the latter case?
You may try
:set fo+=a
which reformats your paragraph as you type.
See :h fo-table.
This might be configurable using formatoptions or formatexpr, but I'm not sure how.
Another solution is to manually format using gq on a visual line selection i.e. add a breakline if the text width is >= tw.
Type in whatever text you like inside another block of text, thus making it 80 chars or more in width
Select the text you think is misformatted using V (Shiftv)
gq
From :h gq:
Format the lines that {motion} moves over.
Formatting is done with one of three methods:
1. If 'formatexpr' is not empty the expression is
evaluated. This can differ for each buffer.
2. If 'formatprg' is not empty an external program
is used.
3. Otherwise formatting is done internally.
In the third case the 'textwidth' option controls the
length of each formatted line (see below).
If the 'textwidth' option is 0, the formatted line
length is the screen width (with a maximum width of
79).
The 'formatoptions' option controls the type of
formatting fo-table.
[..]
For more information on how Vim's textwidth works, take a look at
How to use Vim’s textwidth like a pro

How do I change the character Vim uses to number blank lines in a buffer?

Currently, when my window is bigger than the buffer being displayed, blank lines beyond the end of file are shown with the ~ characters in the line number column. I would prefer for the line number column for those lines to be blank. Is it possible to make it so?
As of Vim 8.0, the color of the filler line character (~) can be changed indepedently by configuring the EndOfBuffer highlight group:
highlight EndOfBuffer ctermfg=bg guifg=bg
Unfortunately, it is not possible to change the tilde character that
Vim uses to show the lines beyond the end of a file (without modifying
the source code).
A viable workaround is to hide those tildes by configuring the
NonText highlight group, which is used for displaying them,
so that its foreground color is the same as the background one:
:highlight NonText ctermfg=bg guifg=bg
However, this approach is not a complete solution, because this
highlighting group is also used for rendering the list characters
(see :help 'list' and :help 'listchars'), making it impossible to
specify highlighting just for the beyond-last-line markings.
Starting with version 8 (see :helpg Patch 7.4.2213), Vim allows
to highlight the filler lines after the last line in a buffer using
a separate highlighting group called EndOfBuffer:
:highlight EndOfBuffer ctermfg=bg guifg=bg

Resources