From 7c34e016bc146af68c9eb6568e4af76735c0f782 Mon Sep 17 00:00:00 2001 From: Olivier Roques Date: Mon, 28 Dec 2020 10:26:40 +0100 Subject: [PATCH] Update README.md --- README.md | 80 +++++++++++++++++++++++++++++++++++++- lua/hardline/parts/git.lua | 5 ++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 44f75d0..4d40005 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,82 @@ A statusline / bufferline for Neovim written in Lua. It is inspired by [vim-airline](https://github.com/vim-airline/vim-airline) but aims to be as light and simple as possible. -This plugin in mainly for my own use. +## Installation + +#### With Packer: +```lua +cmd 'packadd packer.nvim' +return require('packer').startup(function() + use {'ojroques/nvim-hardline'} +end) +``` + +#### With Plug +```vim +call plug#begin() +Plug 'ojroques/nvim-hardline' +call plug#end() +``` + +## Usage +In your *init.lua*: +```lua +require('hardline').setup {} +``` + +If you're using a *.vimrc* or *init.vim*: +```vim +lua require('hardline').setup {} +``` + +## Configuration +You can pass options to the `setup()` function. Here are all available options +with their default settings: +```lua +require('hardline').setup { + bufferline = false, -- enable bufferline + theme = 'default', -- change theme + sections = { -- define sections + {class = 'mode', item = require('hardline.parts.mode').get_item}, + {class = 'high', item = require('hardline.parts.git').get_item, hide = 80}, + '%<', + {class = 'med', item = require('hardline.parts.filename').get_item}, + {class = 'med', item ='%='}, + {class = 'low', item = require('hardline.parts.wordcount').get_item, hide = 80}, + {class = 'error', item = require('hardline.parts.lsp').get_error}, + {class = 'warning', item = require('hardline.parts.lsp').get_warning}, + {class = 'warning', item = require('hardline.parts.whitespace').get_item}, + {class = 'high', item = require('hardline.parts.filetype').get_item, hide = 80}, + {class = 'mode', item = require('hardline.parts.line').get_item}, + }, +} +``` + +You can define your own sections using the `sections` list. Each element of +that list is a table with the following attributes: +* `class`: the section colorscheme. The following classes are currently + available: + * `mode`: change color based on the current mode. + * `low`, `med`, `high`: colors for different levels of importance. + * `bufferline`: colors for the bufferline. + * `error`, `warning`: colors for the diagnostics of Neovim built-in LSP + client. +* `item`: the actual text being displayed. Must be a string or a function + returning a string. +* `hide`: threshold (in number of characters) below which the section will be + hidden. + +## Available section parts +| Part | Description | +|------|-------------| +| `filename` | Filename and file status (readonly, modified, ...) | +| `filetype` | Filetype | +| `git` | Git hunks (requires [vim-gitgutter](https://github.com/airblade/vim-gitgutter)) and Git branch (requires [vim-fugitive](https://github.com/tpope/vim-fugitive)) | +| `line` | Line and column positions | +| `lsp` | Diagnostics from Neovim LSP client | +| `mode` | Current mode | +| `whitespace` | Trailing whitespaces, mixed indent and Git conflict markers warnings | +| `wordcount` | Current word count (enabled only for [some filetypes](https://github.com/ojroques/nvim-hardline/blob/5fc738bb7991f7d7890be14e7a74a50e21f0bd81/lua/hardline/parts/wordcount.lua#L8-L19)) | + +## License +[LICENSE](./LICENSE) diff --git a/lua/hardline/parts/git.lua b/lua/hardline/parts/git.lua index fe5beb1..79da254 100644 --- a/lua/hardline/parts/git.lua +++ b/lua/hardline/parts/git.lua @@ -12,7 +12,7 @@ local function get_hunks() end local function get_branch() - if not g.loaded_gitgutter then return '' end + if not g.loaded_fugitive then return false end local branch = fn.FugitiveHead() return branch ~= '' and string.format('(%s)', branch) or '' end @@ -20,7 +20,8 @@ end local function get_item() local hunks, branch = get_hunks(), get_branch() if branch == '' then return '' end - return table.concat({hunks, ' ' .. branch}) + branch = not branch and '' or ' ' .. branch + return table.concat({hunks, branch}) end return {