• Stars
    star
    6,540
  • Rank 5,793 (Top 0.2 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created over 10 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A light and configurable statusline/tabline plugin for Vim

lightline.vim

A light and configurable statusline/tabline plugin for Vim

https://github.com/itchyny/lightline.vim

powerline (default)

lightline.vim - powerline

wombat

lightline.vim - wombat

solarized (background=dark)

lightline.vim - solarized_dark

solarized (background=light)

lightline.vim - solarized_light

PaperColor (background=dark)

lightline.vim - PaperColor_dark

PaperColor (background=light)

lightline.vim - PaperColor_light

one (background=dark)

lightline.vim - one_dark

one (background=light)

lightline.vim - one_light

For screenshots of all available colorshemes, see this file.

Why yet another clone of powerline?

  • vim-powerline is a nice plugin, but deprecated.
  • powerline is a nice plugin, but difficult to configure.
  • vim-airline is a nice plugin, but it uses too many functions of other plugins, which should be done by users in .vimrc.

Spirit of this plugin

  • Minimalism. The core script is very small to achieve enough functions as a statusline plugin.
  • Configurability. You can create your own component and easily add to the statusline and the tabline.
  • Orthogonality. The plugin does not rely on the implementation of other plugins. Such plugin crossing settings should be configured by users.

Installation

Vim packages (since Vim 7.4.1528)

  1. Clone the plugin with the following command.

     git clone https://github.com/itchyny/lightline.vim ~/.vim/pack/plugins/start/lightline
    

Pathogen

  1. Install with the following command.

     git clone https://github.com/itchyny/lightline.vim ~/.vim/bundle/lightline.vim
    
  2. Generate help tags with :Helptags.

Vundle

  1. Add the following configuration to your .vimrc.

     Plugin 'itchyny/lightline.vim'
    
  2. Install with :PluginInstall.

NeoBundle

  1. Add the following configuration to your .vimrc.

     NeoBundle 'itchyny/lightline.vim'
    
  2. Install with :NeoBundleInstall.

vim-plug

  1. Add the following configuration to your .vimrc.

     Plug 'itchyny/lightline.vim'
    
  2. Install with :PlugInstall.

dein.vim

  1. Add the following configuration to your .vimrc.

     call dein#add('itchyny/lightline.vim')
    
  2. Install with :call dein#install()

Introduction

After installing this plugin, you restart the editor and will get a cool statusline. lightline.vim - tutorial

The color of the statusline changes due to the mode of Vim. Try typing something, selecting in visual mode and replacing some texts.

If the statusline looks like lightline.vim - tutorial

add the following configuration to your .vimrc.

set laststatus=2

If the statusline is not coloured like lightline.vim - tutorial

then modify TERM in your shell configuration (.zshrc for example)

export TERM=xterm-256color

and then add the following configuration to your .vimrc.

if !has('gui_running')
  set t_Co=256
endif

Your statusline appears to work correctly? If yes, great, thanks for choosing lightline.vim! If no, please file an issue report to the issue tracker.

By the way, -- INSERT -- is unnecessary anymore because the mode information is displayed in the statusline. lightline.vim - tutorial If you want to get rid of it, configure as follows.

set noshowmode

Colorscheme configuration

The lightline.vim plugin provides multiple colorschemes to meet your editor colorscheme. Do not be confused, editor colorscheme rules how codes look like in buffers and lightline.vim has independent colorscheme feature, which rules how the statusline looks like.

If you are using wombat colorscheme, add the following setting to your .vimrc,

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ }

restart Vim and the statusline looks like:

lightline.vim - tutorial

If the colors of the statusline do not change, move the settings of g:lightline before setting the editor colorscheme.

There are many lightline colorschemes available as screenshots shown above. See :h g:lightline.colorscheme for the complete list.

Advanced configuration

The default appearance of lightline.vim is carefully designed that the tutorial is enough here for most people. So please read this section if you really want to configure and enjoy the configurability of lightline.vim.

Sometimes people want to display information of other plugins. For example git branch information, syntax check errors and some statuses of plugins.

The lightline.vim plugin does not provide any plugin integration by default. This plugin considers orthogonality to be one of the important ideas, which means that the plugin does not rely on implementation of other plugins. Once a plugin starts to integrate with some famous plugins, it should be kept updated to follow the changes of the plugins, and should accept integration requests with new plugins and it will suffer from performance regression due to plugin availability checks.

Instead, lightline.vim provides a simple API that user can easily integrate with other plugins. Once you understand how to configure and how it will be displayed in the statusline, you can also tell how to integrate with your favorite plugins.

Let's start to configure the appearance. The statusline is composed of multiple components. It shows the current mode, filename, modified status on the left, and file format, encoding, filetype and cursor positions on the right. So in order to add something in the statusline, you firstly create a new component and specify the place.

This is the hello world of lightline.vim component.

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'readonly', 'filename', 'modified', 'helloworld' ] ]
      \ },
      \ 'component': {
      \   'helloworld': 'Hello, world!'
      \ },
      \ }

The statusline will look like: lightline.vim - tutorial

You have succeeded in displaying Hello, world! in the statusline. The helloworld component is added to g:lightline.active.left and its content is configured in g:lightline.component. The component contents are simply added to &statusline. Try :echo &statusline, it might be a little bit complicated, but you will find Hello, world! somewhere.

You can use 'statusline' syntax for lightline.vim components. Consult :h 'statusline' to see what's available here. For example, if you want to print the value of character under the cursor in hexadecimal, configure as

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'readonly', 'filename', 'modified', 'charvaluehex' ] ]
      \ },
      \ 'component': {
      \   'charvaluehex': '0x%B'
      \ },
      \ }

lightline.vim - tutorial

You want the character value information on the right hand side? OK, configure as

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'active': {
      \   'right': [ [ 'lineinfo' ],
      \              [ 'percent' ],
      \              [ 'fileformat', 'fileencoding', 'filetype', 'charvaluehex' ] ]
      \ },
      \ 'component': {
      \   'charvaluehex': '0x%B'
      \ },
      \ }

lightline.vim - tutorial

We have learned how to add a simple component.

  • See :h 'statusline' to check the statusline flags.
  • Add a new component to g:lightline.component.
  • Add the component name to g:lightline.active.left or g:lightline.active.right.

You can also configure the statusline of inactive buffers by adding the component to g:lightline.inactive.left or g:lightline.inactive.right.

Now let's add some integrations with other plugin. The name of the git branch is important these days. But lightline.vim does not provide this information by default because it is also one of plugin crossing configurations, and not all people want the integration.

In order to show the branch name in the statusline, install some plugins which provide the branch information. The vim-fugitive plugin is a famous plugin so let's integrate lightline.vim with it. If you don't like to install full git integration but just want to display the branch name in the statusline, you can use the vim-gitbranch plugin which provides gitbranch#name function.

let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
      \ },
      \ 'component_function': {
      \   'gitbranch': 'FugitiveHead'
      \ },
      \ }

lightline.vim - tutorial

Okay, now the statusline shows that we are coding at the master branch. What do we learn from this example?

  • Find out the function which is suitable to use in the statusline.
  • Create a function component. The previous charvaluehex component has 'statusline' item configuration and registered in g:lightline.component. In the current example, we register the name of the function in g:lightline.component_function. It should return the string to be displayed in the statusline.
  • Add the component name gitbranch to g:lightline.active.left or g:lightline.active.right.

Here we have leaned two kinds of components.

  • component: it has a %-prefixed item which you can find the meaning at :h 'statusline'. All the default components of lightline.vim are components in this style. See the default components at :h g:lightline.component.
  • function component: the name of functions are registered. The function is called again and again so be careful not to register a heavy function. See the help with :h g:lightline.component_function.

The function component is an important design for the configurability of lightline.vim. By providing the configuration interface via functions, you can adjust the statusline information as you wish. For the proof, let's look into some configuration examples in Q&A style.

Can I hide the readonly component in the help buffer?

Yes, create a function component for readonly. The configuration of function component has priority over the default component.

let g:lightline = {
      \ 'component_function': {
      \   'readonly': 'LightlineReadonly',
      \ },
      \ }

function! LightlineReadonly()
  return &readonly && &filetype !=# 'help' ? 'RO' : ''
endfunction

lightline.vim - tutorial

Can I hide the readonly component in other plugins buffer?

Yes, modify the LightlineReadonly function as you wish.

function! LightlineReadonly()
  return &readonly && &filetype !~# '\v(help|vimfiler|unite)' ? 'RO' : ''
endfunction

let g:unite_force_overwrite_statusline = 0
let g:vimfiler_force_overwrite_statusline = 0

lightline.vim - tutorial

Can I display the plugin information at the filename component?

Yes, overwrite the filename component.

let g:lightline = {
      \ 'component_function': {
      \   'filename': 'LightlineFilename',
      \ },
      \ }

function! LightlineFilename()
  return &filetype ==# 'vimfiler' ? vimfiler#get_status_string() :
        \ &filetype ==# 'unite' ? unite#get_status_string() :
        \ &filetype ==# 'vimshell' ? vimshell#get_status_string() :
        \ expand('%:t') !=# '' ? expand('%:t') : '[No Name]'
endfunction

let g:unite_force_overwrite_statusline = 0
let g:vimfiler_force_overwrite_statusline = 0
let g:vimshell_force_overwrite_statusline = 0

lightline.vim - tutorial

Can I display the plugin name at the mode component?

Yes, overwrite the mode component.

let g:lightline = {
      \ 'component_function': {
      \   'mode': 'LightlineMode',
      \ },
      \ }

function! LightlineMode()
  return expand('%:t') =~# '^__Tagbar__' ? 'Tagbar':
        \ expand('%:t') ==# 'ControlP' ? 'CtrlP' :
        \ &filetype ==# 'unite' ? 'Unite' :
        \ &filetype ==# 'vimfiler' ? 'VimFiler' :
        \ &filetype ==# 'vimshell' ? 'VimShell' :
        \ lightline#mode()
endfunction

lightline.vim - tutorial

Can I trim the file format and encoding information on narrow windows?

Yes, check winwidth(0) and return empty string with some threshold.

let g:lightline = {
      \ 'component_function': {
      \   'fileformat': 'LightlineFileformat',
      \   'filetype': 'LightlineFiletype',
      \ },
      \ }

function! LightlineFileformat()
  return winwidth(0) > 70 ? &fileformat : ''
endfunction

function! LightlineFiletype()
  return winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : 'no ft') : ''
endfunction

lightline.vim - tutorial

Can I trim the bar between the filename and modified sign?

Yes, by joining the two components.

let g:lightline = {
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'readonly', 'filename' ] ],
      \ },
      \ 'component_function': {
      \   'filename': 'LightlineFilename',
      \ },
      \ }

function! LightlineFilename()
  let filename = expand('%:t') !=# '' ? expand('%:t') : '[No Name]'
  let modified = &modified ? ' +' : ''
  return filename . modified
endfunction

lightline.vim - tutorial

You can control the visibility and contents by writing simple functions. Now you notice how much function component is important for the configurability of lightline.vim.

more tips

Mode names are too long. Can I use shorter mode names?

Yes, configure g:lightline.mode_map.

let g:lightline = {
      \ 'mode_map': {
        \ 'n' : 'N',
        \ 'i' : 'I',
        \ 'R' : 'R',
        \ 'v' : 'V',
        \ 'V' : 'VL',
        \ "\<C-v>": 'VB',
        \ 'c' : 'C',
        \ 's' : 'S',
        \ 'S' : 'SL',
        \ "\<C-s>": 'SB',
        \ 't': 'T',
        \ },
      \ }

How can I truncate the components from the right in narrow windows?

Please include %< to one of the right components.

let g:lightline = {
      \ 'component': {
      \   'lineinfo': '%3l:%-2v%<',
      \ },
      \ }

Where can I find the default components?

See :h g:lightline.component.

Note for developers of other plugins

Appearance consistency matters.

The statusline is an important space for Vim users. Overwriting the statusline forcibly in your plugin is not a good idea. It is not hospitality, but just an annoying feature. If your plugin has such a feature, add an option to be modest.

A good design is as follows. Firstly, give the users a clue to judge which buffer is the one your plugin creates. The filename is a manner and the filetype is another. Then, export a function which is useful to be shown in the statusline. Lastly, for advanced users, set important information in buffer variables so that the users can obtain the condition of the plugin easily.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

More Repositories

1

gojq

Pure Go implementation of jq
Go
3,016
star
2

calendar.vim

A calendar application for Vim
Vim Script
1,904
star
3

bed

Binary editor written in Go
Go
1,134
star
4

mmv

rename multiple files with editor
Go
724
star
5

vim-cursorword

Underlines the word under the cursor
Vim Script
581
star
6

sjsp

Simple JavaScript Profiler
Haskell
234
star
7

vim-gitbranch

Provides the branch name of the current git repository
Vim Script
199
star
8

rexdep

Roughly extract dependency relation from source code
Go
171
star
9

timefmt-go

Efficient time formatting library (strftime, strptime) for Golang
Go
165
star
10

fillin

fill-in your command and execute
Go
142
star
11

landscape.vim

A colorscheme for Vim
Vim Script
137
star
12

maze

A maze command written in Go
Go
115
star
13

base58-go

Base58 encoding/decoding package and command written in Go
Go
106
star
14

vim-haskell-indent

If the plugin does not work for some syntax, feel free to report to the issue tracker!
Vim Script
105
star
15

thumbnail.vim

A thumbnail-style buffer selector for Vim
Vim Script
101
star
16

volume-go

Cross-platform audio volume control library for Go
Go
72
star
17

rassemble-go

Go implementation of Regexp::Assemble
Go
67
star
18

vim-qfedit

Edit the quickfix/location list freely
Vim Script
65
star
19

miv

Vim plugin manager written in Haskell
Haskell
65
star
20

vim-parenmatch

An efficient alternative to the standard matchparen plugin
Vim Script
59
star
21

json2yaml

An efficient JSON to YAML converter written in Go language
Go
58
star
22

dictionary.vim

Dictionary.app interface for Vim
Vim Script
58
star
23

screensaver.vim

Screensavers for Vim
Vim Script
53
star
24

gojo

Yet another Go implementation of jo
Go
49
star
25

fastinvsqrt

Fast inverse square root in programming languages
Makefile
49
star
26

github-migrator

GitHub repository migrator
Go
46
star
27

vim-highlighturl

URL highlight everywhere
Vim Script
45
star
28

dotfiles

my dotfiles
Vim Script
37
star
29

llvm-brainfuck

Brainfuck compiler based on LLVM API
C++
35
star
30

mkrg

Mackerel graph viewer in terminal
Go
34
star
31

qhs

SQL queries on CSV and TSV files
Haskell
33
star
32

lightline-powerful

Powerful settings for lightline.vim
Vim Script
26
star
33

procout

procout peeks write(2) of another process using ptrace(2), written in Rust
Rust
26
star
34

event-go

Simple synchronous event pub-sub package for Golang
Go
20
star
35

github-better-header

Brings back a better GitHub header
HTML
20
star
36

cam

unix command cam: view images inside terminal
C
20
star
37

vim-winfix

Fix the focus and the size of windows in Vim
Vim Script
18
star
38

setup

DO NOT USE THIS
Shell
15
star
39

pihex-rs

Arbitrary place hexadecimal digits viewer of pi written in Rust
Rust
15
star
40

vim-gof

Vim Script
14
star
41

minivm

C
13
star
42

vim-external

Switch to external applications from Vim
Vim Script
11
star
43

mackerel-plugin-rs

Mackerel plugin helper library for Rust
Rust
11
star
44

jsparser

A JavaScript parser in JavaScript generated by Jison
CoffeeScript
11
star
45

ChromePlayer

A music player for local files, working on Google Chrome
JavaScript
11
star
46

screensaver.c

A clock screensaver in terminal
C
9
star
47

uptime-rs

Multi-platform uptime library for Rust
Rust
9
star
48

astgen-go

interface{} => ast.Node
Go
8
star
49

golang-simple-server-sample

A simple server sample in Go
Go
8
star
50

vim-pdf

pdf filetype plugin for Vim
Vim Script
8
star
51

shell-function-and

shell function: and
8
star
52

vim-grep

The only grep in Vim that I need...
Vim Script
8
star
53

zshhist-go

zsh histfile utility for Go
Go
7
star
54

brainfuck

brainfuck
Brainfuck
7
star
55

bin

My utility executables.
Shell
7
star
56

git-branch-name

Optimally fast branch name command for Git.
C
7
star
57

homebrew-tap

Homebrew formulae
Ruby
6
star
58

mackerel-client-rs

An API client library for Mackerel written in Rust (still in the developing stage; host APIs are not implemented yet)
Rust
6
star
59

minivm-go

Golang implementation of a stack-machine based programming language interpreter
Go
6
star
60

maze-c

unix command maze: generating a maze
C
6
star
61

vim-haskell-sort-import

Sort import statements in Haskell codes
Haskell
6
star
62

mackerel-plugin-battery

Battery plugin for Mackerel
Go
5
star
63

vim-closebuffer

Close buffers in Vim
Vim Script
5
star
64

vim-extracmd

Define extra commands.
Vim Script
5
star
65

unite-preview

A preview plugin for vimfiler, unite
Vim Script
4
star
66

mackerel-client-hs

Mackerel API client in Haskell
Haskell
4
star
67

2bf

2bf - generates a Brainfuck code
C
4
star
68

vim-term

Vim Script
3
star
69

maketen-go

Create 10 from numbers!
Go
3
star
70

fractal

fractal figures in gnuplot
3
star
71

vim-cmdline-ranges

Quickly start/edit cmdline-ranges in Vim
Vim Script
3
star
72

Filter.js

A sample of image processing with JavaScript and canvas
JavaScript
3
star
73

vim-quickrun-lightline-hooks

Vim Script
3
star
74

vim-autoft

Set filetype automatically in Vim
Vim Script
3
star
75

tie

Go
3
star
76

procalive

procalive keeps your process alive
Rust
3
star
77

zsh-auto-fillin

Automatic fillin https://github.com/itchyny/fillin
Shell
3
star
78

s3-cache-action

GitHub Action to save cache files and restore them from Amazon S3
TypeScript
3
star
79

c2bf.hs

Convert C to Brainfuck (not working, deprecated product)
Haskell
2
star
80

homebrew-rexdep

Deprecated in favor of https://github.com/itchyny/homebrew-tap
2
star
81

vim-extra-snippets

My own snippets
Vim Snippet
2
star
82

vim-cmdline-escape

Escape special characters on cmdline
Vim Script
2
star
83

setupfiles-go

Create files and directories easily for tests in Go
Go
2
star
84

bf

bf - executes a Brainfuck code
C
2
star
85

syscall-study

Go
2
star
86

vim-histexclude

Exclude by patterns from the histories.
Vim Script
2
star
87

vim-spellbad-pattern

Register regexps to SpellBad
Vim Script
2
star
88

mackerel-plugin-dice-sh

Dice plugin for Mackerel
Shell
2
star
89

unite-auto-open

starting or opening files action for unite
Vim Script
2
star
90

mtimedir

Go
2
star
91

sbt-compile-warn

Aggregate sbt compile warnings
Go
2
star
92

itchyny

itchyny's profile page
2
star
93

codeforces

Codeforces in Haskell
Haskell
2
star
94

browsershell

A shell in your browser
JavaScript
2
star
95

autolatex

A shell script to compile a LaTeX file
Shell
2
star
96

formulate

Homebrew formula managing script
Shell
2
star
97

unite-changetime

An action for unite/vimfiler, changing modified time of a file
Vim Script
1
star
98

mmpp

Mackerel metric pretty printer
Rust
1
star
99

atcoder

AtCoder in Rust
Rust
1
star
100

mackerel-plugin-dice-rs

Dice plugin example using mackerel-plugin-rs
Rust
1
star