sponsor Vim development Vim logo Vim Book Ad

StatusLineHighlight : Change statusline color depending on buffer state.

 script karma  Rating 21/8, Downloaded by 1070  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
This plugin indicates the state of the buffer (modified, readonly,
unmodifiable, special non-file "scratch") / window (is preview window) by
changing the highlighting of the window's status line. It defines additional
StatusLine... / StatusLine...NC highlight groups that are customizable and by
default use different colors to differentiate the buffer states.

This screenshot shows the plugin in action:
    https://raw.githubusercontent.com/inkarkat/vim-StatusLineHighlight/master/doc/StatusLineHighlight.png

HOW IT WORKS
Using different colors for the status line is trickier than it seems: Though
the 'statusline' setting supports inline expressions via %{expr}, the returned
text is taken as-is; highlight items %#hlgroup# and #* are not evaluated, only
printed as text. Evaluation does happen when one %!expr is used, but the
expression seems to be evaluated only once for a complete screen redraw cycle,
not for each individual status line, so one cannot use it to set different
highlightings for different status lines.

Therefore, this plugin sets up autocmds that continually adapt buffer-local
'statusline' settings (which prepend the highlight group to the (mostly)
global setting (though local 'statusline' settings set by ftplugins are kept,
too)).

USAGE
This plugin does not introduce any commands or mappings. Just observe the
changed status line colors, e.g. when using :view, :pedit, :help, etc.

You immediately see that a buffer is read-only because its status line is
gray, not black; unmodifiable buffers are even "more" gray. Unsaved, modified
buffers are indicated via a dark-red status line. Special windows like the
command and quickfix windows, as well as many "scratch" buffers used by
plugins are shown in dark blue. The preview window is now also easy to find,
because it has a blue status line.
 
install details
INSTALLATION
The code is hosted in a Git repo at
    https://github.com/inkarkat/vim-StatusLineHighlight
You can use your favorite plugin manager, or "git clone" into a directory used
for Vim packages. Releases are on the "stable" branch, the latest unstable
development snapshot on "master".

This script is also packaged as a vimball. If you have the "gunzip"
decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise,
decompress the archive first, e.g. using WinZip. Inside Vim, install by
sourcing the vimball or via the :UseVimball command.
    vim StatusLineHighlight*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.

CONFIGURATION
For a permanent configuration, put the following commands into your vimrc:

You may override the default highlightings and define your own colors in the
following form (after any :colorscheme command). As with the built-in status
line highlighting, there is a hl-StatusLine group for the current window and
a hl-StatusLineNC for all non-current windows.
    highlight StatusLineModified           term=bold,reverse cterm=bold,reverse ctermfg=DarkRed  gui=bold,reverse guifg=DarkRed
    highlight StatusLineModifiedNC         term=reverse      cterm=reverse      ctermfg=DarkRed  gui=reverse      guifg=DarkRed
    highlight StatusLinePreview            term=bold,reverse cterm=bold,reverse ctermfg=Blue     gui=bold,reverse guifg=Blue
    highlight StatusLinePreviewNC          term=reverse      cterm=reverse      ctermfg=Blue     gui=reverse      guifg=Blue
    highlight StatusLineReadonly           term=bold,reverse cterm=bold,reverse ctermfg=Grey     gui=bold,reverse guifg=DarkGrey
    highlight StatusLineReadonlyNC         term=reverse      cterm=reverse      ctermfg=Grey     gui=reverse      guifg=DarkGrey
    highlight StatusLineSpecial            term=bold,reverse cterm=bold,reverse ctermfg=DarkBlue gui=bold,reverse guifg=DarkBlue
    highlight StatusLineSpecialNC          term=reverse      cterm=reverse      ctermfg=DarkBlue gui=reverse      guifg=DarkBlue
    highlight StatusLineUnmodifiable       term=bold,reverse cterm=bold,reverse ctermfg=Grey     gui=bold,reverse guifg=Grey
    highlight StatusLineUnmodifiableNC     term=reverse      cterm=reverse      ctermfg=Grey     gui=reverse      guifg=Grey
If you want to avoid losing the highlightings on :colorscheme commands, you
need to re-apply your highlights on the ColorScheme event, similar to how
this plugin does.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
StatusLineHighlight-1.10.vmb.gz 1.10 2018-11-05 7.0 Ingo Karkat - ENH: Handle hl-User1..9 highlighting by replacing %* and %0* with the custom statusline highlighting. Previously, the custom statusline highlighting provided by this plugin stopped after the end of a User highlighting.
- Minor: Make substitute() robust against 'ignorecase'.
StatusLineHighlight.vba.gz 1.01 2011-07-01 7.0 Ingo Karkat Avoid losing the statusline highlightings on colorscheme commands.
StatusLineHighlight.vba.gz 1.00 2010-12-27 7.0 Ingo Karkat Initial upload
ip used for rating: 54.167.112.42

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
OSDN.net Logo