Highlight the part of a line that doesn't fit into textwidth
(or really,
whatever width you like).
I've had this functionality in my .vimrc
for a long time, and finally decided
to extract it into a plugin. The idea is extremely simple, a gazillion examples
of how to to this can be found online, but still... I like making plugins.
I had stopped maintaining this project but the superkind Francisco (@oblitum) stepped up and offered to take over maintenance, so he's the maintainer now. Thanks Francisco! π
I personally moved from Vundle to vim-plug a while ago and never looked back. Anyways, whatever floats your boat:
" vim-plug
Plug 'whatyouhide/vim-lengthmatters'
" NeoBundle
NeoBundle 'whatyouhide/vim-lengthmatters'
" Vundle
Plugin 'whatyouhide/vim-lengthmatters'
You pathogen dinosaurs can just clone the repo:
git clone https://github.com/whatyouhide/vim-lengthmatters.git ~/.vim/bundle
The highlighting functionality operates always on a per-window basis, meaning you can keep it enabled on a window and disabled on another one at the same time.
By default, it's based on the value of the textwidth
option (it feels
right), but this can be changed in the options. See :h 'textwidth'
for more
infos.
The plugin provides a bunch of commands:
:LengthmattersToggle
: toggle the highlighting for the current window:LengthmattersEnable
: enable the highlighting for the current window:LengthmattersDisable
: disable the highlighting for the current window:LengthmattersReload
: force reloading (useful if something goes wrong, ortextwidth
changes, or god knows what):LengthmattersEnableAll
: enable the highlighting for all open windows:LengthmattersDisableAll
: disable the highlighting for all open windows
To set a variable in vim (for example g:foo
to the string foo
), just do:
let g:foo = 'foo'
Most of the configuration for this plugin can be done through a handful of variables. The only thing you have to use functions for is highlighting. Read the relative section for how to do it.
(defaults to !&diff
)
If this variable is set to 0
, no highlighting will be done
when opening a new window. Highlighting can still be activated with one of the
previously mentioned commands.
(defaults to 81
)
The value of this variable is the first character to be highlighted; the
highlighting will continue until the end of the line. This means that if it's
okay for lines to be 40
characters long (because you're from 1920 or
something) you set this variable to 41
.
(defaults to 1
)
Whether to highlight based on the value of textwidth
. If textwidth
is not
set, it will fall back to g:lengthmatters_start_at_column
.
(defaults to
['unite', 'tagbar', 'startify', 'gundo', 'vimshell', 'w3m', 'nerdtree', 'help', 'qf', 'dirvish']
)
A list of filetypes for which the highlighting isn't (and can't be) enabled.
They're regular expressions, so, for example, to disable highlighting in any
helper debug window of vim-go, one can add
'godebug.*'
to the list.
(defaults to 1
)
If this variable is set to 1
, no highlighting will be done when opening a
read-only file.
(defaults to 'OverLength'
)
The name of the syntax element that will be used to highlight and match the
overly long lines.
(defaults to 0
)
Only highlight one column instead of all columns up to EOL.
The plugin provides a default highlighting which is based on the current
colorscheme. The foreground color is taken from the background color of the
Normal
highlight group, while the background color is taken from the
foreground color of the Comment
group. This should look decent on pretty
much every colorscheme.
If you want to change that, you have two options.
To change the actual colors, use the lengthmatters#highlight
function:
call lengthmatters#highlight('ctermbg=3 ctermfg=10')
To link the group to another highlight group, use the
lengthmatters#highlight_link_to
function:
call lengthmatters#highlight_link_to('ColorColumn')
Note that you have to use one of these two functions in order to manipulate the highlighting, since the plugin performs some dark magic behind the scenes in order to keep the highlighting (and you) happy.
The highlighting is reloaded when you call one of the functions, just as if you
called :LengthmattersReload
.
Different line length in different file types can be achieved with the
textwidth
variable. For example, if the default line is 80 characters
and we want to have a line length of 120 characters only in Java files,
we can do it like this:
autocmd bufreadpre *.java setlocal textwidth=120
If you want to test this plugin, be sure you have vader.vim installed,
then open tests/lengthmatters.vader
and run :Vader
.
Β© Andrea Leopardi