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 personally moved from Vundle to vim-plug a while ago and never looked back. Anyways, whatever floats your boat:
" vim-plug
Plug 'scps950707/vim-lengthmatters'
" NeoBundle
NeoBundle 'scps950707/vim-lengthmatters'
" Vundle
Plugin 'scps950707/vim-lengthmatters'
You pathogen dinosaurs can just clone the repo:
git clone https://github.com/scps950707/vim-lengthmatters.git ~/.vim/bundle
The highlighting functionality operates always on a per-buffer basis.
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:
:LengthmattersInit
: init the highlighting for the current window: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
(defaults to 1
)
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 []
)
A list of filetypes for which the highlighting isn't (and can't be) enabled.
(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.
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
.
If you want to test this plugin, be sure you have vader.vim installed,
then open tests/lengthmatters.vader
and run :Vader
.
© Andrea Leopardi