Git Product home page Git Product logo

vim-modusline's Introduction

Modusline: Mode-specific statusline colors

This plugin adds mode-specific coloring to your existing statusline so you can visually distinguish (screenshots below) which mode Vim is currently in.

Setup

Install this plugin using your favorite Vim plugin manager and restart Vim. Now change Vim modes and observe the statusline changing colors accordingly. That's all! For customization, read about Variables and Functions below.

Preview

 'n'      Normal mode                'no'     Operator-pending mode      'v'      Visual mode, by character  'V'      Visual mode, by line       <C-V>    Visual mode, blockwise     's'      Select mode, by character  'S'      Select mode, by line       <C-S>    Select mode, blockwise     'i'      Insert mode                'ic'     Insert mode completion     'R'      Replace mode               'Rc'     Replace mode completion    'Rv'     Replace mode virtual       'c'      Command mode               't'      Terminal mode

Variables

You can redefine any of these variables per your customization needs.

&statusline

You can define your own custom statusline (the default one is shown below) and this plugin will automatically add mode-specific colors & labels to it.

By default, this variable is defined as follows, unless you override it:

set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

g:modusline_set_ls

You can assign 0 to this variable to prevent this plugin from changing the laststatus setting to always show the statusline for bottom-most windows:

let g:modusline_set_ls = 0

g:modusline_colors

A dictionary that maps mode() values to %#HLname# statusline colors. If there is no entry for a particular mode() value in the dictionary, then this plugin falls back to using jarring %#ErrorMsg# as the color.

For a list of possible HLname values, run the Vim :highlight command.

By default, this variable is defined as follows, unless you override it:

let g:modusline_colors           = {}              " see :help mode()
let g:modusline_colors['n']      = ''              " Normal
let g:modusline_colors['no']     = '%#DiffChange#' " Operator-pending
let g:modusline_colors['v']      = '%#DiffText#'   " Visual by character
let g:modusline_colors['V']      = '%#DiffText#'   " Visual by line
let g:modusline_colors["\<C-V>"] = '%#DiffText#'   " Visual blockwise
let g:modusline_colors['s']      = '%#WildMenu#'   " Select by character
let g:modusline_colors['S']      = '%#WildMenu#'   " Select by line
let g:modusline_colors["\<C-S>"] = '%#WildMenu#'   " Select blockwise
let g:modusline_colors['i']      = '%#DiffAdd#'    " Insert
let g:modusline_colors['R']      = '%#DiffDelete#' " Replace |R|
let g:modusline_colors['Rv']     = '%#DiffDelete#' " Virtual Replace |gR|
let g:modusline_colors['c']      = '%#Search#'     " Command-line
let g:modusline_colors['cv']     = '%#MatchParen#' " Vim Ex mode |gQ|
let g:modusline_colors['ce']     = '%#MatchParen#' " Normal Ex mode |Q|
let g:modusline_colors['r']      = '%#Todo#'       " Hit-enter prompt
let g:modusline_colors['rm']     = '%#Todo#'       " The -- more -- prompt
let g:modusline_colors['r?']     = '%#Todo#'       " A |:confirm| query of some sort
let g:modusline_colors['!']      = '%#IncSearch#'  " Shell or external command is executing
let g:modusline_colors['t']      = '%#DiffAdd#'    " Terminal mode: keys go to the job
let g:modusline_colors['ic']     = '%#DiffChange#' " see :help ins-completion
let g:modusline_colors['Rc']     = '%#DiffChange#' " see :help ins-completion

g:modusline_labels

A dictionary that maps mode() values to user-friendly labels (strings). If there is no entry for a particular mode() value in the dictionary, then this plugin falls back to using that mode() value as the label.

By default, this variable is defined as follows, unless you override it:

let g:modusline_labels = {}

Functions

You can redefine any of these functions per your customization needs.

Modusline(statusline)

Adds mode-specific colors and labels to the given statusline and returns a new statusline expression that you can assign via :set statusline=.

function! Modusline(statusline) abort
  let modus = mode(1)
  let color = ModuslineColor(modus)
  let label = ModuslineLabel(modus)
  return ModuslineMerge(a:statusline, modus, color, label)
endfunction

ModuslineColor(modus)

Returns a %#HLname# statusline color for the given mode() value by referencing the g:modusline_colors dictionary, as described earlier: If there is no entry for a particular mode() value in the dictionary, then this plugin falls back to using jarring %#ErrorMsg# as the color.

function! ModuslineColor(modus) abort
  return get(g:modusline_colors, a:modus, '%#ErrorMsg#')
endfunction

ModuslineLabel(modus)

Returns a user-friendly label (string) for the given mode() value by referencing the g:modusline_labels dictionary, as described earlier: If there is no entry for a particular mode() value in the dictionary, then this plugin falls back to using that mode() value as the label.

function! ModuslineLabel(modus) abort
  return get(g:modusline_labels, a:modus, a:modus)
endfunction

ModuslineMerge(statusline, modus, color, label)

Returns a statusline expression built up from all the pieces passed in.

function! ModuslineMerge(statusline, modus, color, label) abort
  return a:color .''. a:label .''. a:statusline
endfunction

References

License

Like my work? 👍 Please spare a life today as thanks! :cow::pig::chicken::fish::speak_no_evil::v::revolving_hearts:

Copyright 2018 Suraj N. Kurapati https://github.com/sunaku

Distributed under the same terms as Vim itself.

vim-modusline's People

Contributors

sunaku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vim-modusline's Issues

g:modusline_colors['t'] overrides StatusLineTerm on my colorscheme

I installed your plugin, because I wanted to have statusline colors but use a custom statusline, and it worked rather well. However, when I attempted to use the terminal, the color specified by vim-modusline (DiffAdd) overrode the existing color of my terminal statusline, which is defined by StatusLineTerm in the colorscheme I use.
I attach two images to show how the terminal inside vim looks before and after the installation of the plugin.
Before:
statuslineterm-before-modusline
After:
statuslineterm-after-modusline

If possible, I would like to be able to use the color I set myself, since it fits better with my overall theme (not to mention that DiffAdd is by default also used on insert mode, which can be confusing). I'm aware that I can just set let g:modusline_colors['t'] = '' to remedy this problem, -> edit: scratch that, I can't - when I try this, or the alternative let g:modusline_colors['t'] = '%#StatusLineTerm#' , vim basically fails to open.
I believe it would be better if the plugin somehow didn't override the default color if it spotted StatusLineTerm being defined.

System details: gVim 8.1.647 on Linux Mint MATE 18.3 (based on Ubuntu 16.04).
P.S. The same problem applies for me in terminal vim as well, but only because I use a terminal that supports true color and enable set termguicolors in my vimrc, because my colorscheme is more geared towards the gui.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.