Skip to content

scps950707/vim-lengthmatters

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lengthmatters.vim

Build Status Average time to resolve an issue Percentage of issues still open

Highlight the part of a line that doesn't fit into textwidth (or really, whatever width you like).

screenshot

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.

Installation

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

What's in it

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, or textwidth changes, or god knows what)
  • :LengthmattersEnableAll: enable the highlighting for all open windows
  • :LengthmattersDisableAll: disable the highlighting for all open windows

Configuration

g:lengthmatters_on_by_default

(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.

g:lengthmatters_start_at_column

(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.

g:lengthmatters_use_textwidth

(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.

g:lengthmatters_excluded

(defaults to [])

A list of filetypes for which the highlighting isn't (and can't be) enabled.

g:lengthmatters_exclude_readonly

(defaults to 1) If this variable is set to 1, no highlighting will be done when opening a read-only file.

g:lengthmatters_match_name

(defaults to 'OverLength') The name of the syntax element that will be used to highlight and match the overly long lines.

Highlighting

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.

lengthmatters#highlight

To change the actual colors, use the lengthmatters#highlight function:

call lengthmatters#highlight('ctermbg=3 ctermfg=10')
lengthmatters#highlight_link_to

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.

Testing

If you want to test this plugin, be sure you have vader.vim installed, then open tests/lengthmatters.vader and run :Vader.

Maintainer

scps950707

License

© Andrea Leopardi

About

Highlight the flooding part of an overly long line.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Vim Script 100.0%