shellRaining/hlchunk.nvim

github github
pluginformattingindent
star 23
alert-circle 3
users 1
git-branch 0
CREATED

2023-02-12

UPDATED

15 days ago


This is the lua implementation of nvim-hlchunk, and add some new features like highlighting indentline, specially thanks indent-blankline.nvim, during the process of writing this plugin, this repo provided a lot of help and inspiration for me

brief

this plugin now have four parts (future will add more... ^v^)

  1. hl_chunk
  2. hl_indent
  3. hl_line_num
  4. hl_blank

the first one is to highlight the current chunk, a chunk is defined as the closest pair of curly braces and the code in between, so it might not work very well in lua or python source code. In the future, I might define a chunk by using indentation (so, this plugin may become another indent_blankline in the future 😊)

the second one is to highlight indentline like indent_blankline, you can choose a different indent render mode, one is base treesitter, another is base on the number of blank. the advantage of treeitter is that it is very accurate, but it may have low performance, and doesn't support some filetype, such as markdown, if you choose the latter mode, it will render faster (maybe), but will have some issues in particular situation, example below.

base on blank number

base on treesitter

the third one is similar to hl_chunk, the difference is that it will highlight line number, you can set front color or background color for it

the last one is hl_blank, which can highlight the blank with some funny char and style, you can see in the example below, you can find many useful chars in this website Unicode Plus

example

NOTE: you can click the picture to get more information about how to configure like this

hl_chunk

hl_indent

hl_line_num

hl_blank

Requirements

neovim version >= 0.7.0 (maybe, just test at this version)

Installation

Packer

use { "shellRaining/hlchunk.nvim" }

Plug

Plug "shellRaining/hlchunk.nvim"

Setup

The script comes with the following defaults:

{
    chunk = {
        enable = true,
        support_filetypes = {
            "*.ts",
            "*.js",
            "*.json",
            "*.go",
            "*.c",
            "*.cpp",
            "*.rs",
            "*.h",
            "*.hpp",
            "*.lua",
            "*.vue",
        },
        chars = {
            horizontal_line = "─",
            vertical_line = "│",
            left_top = "â•­",
            left_bottom = "â•°",
            right_arrow = ">",
        },
        style = "#00ffff",
    },

    indent = {
        enable = true,
        use_treesitter = false,
        -- You can uncomment to get more indented line look like
        chars = {
            "│",
        },
        -- you can uncomment to get more indented line style
        style = {
            vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("Whitespace")), "fg", "gui"),
        },
        exclude_filetype = {
            dashboard = true,
            help = true,
            lspinfo = true,
            packer = true,
            checkhealth = true,
            man = true,
            mason = true,
            NvimTree = true,
            plugin = true,
        },
    },

    line_num = {
        enable = true,
        support_filetypes = {
            "..."
        },
        style = "#806d9c",
    },

    blank = {
        enable = true,
        chars = {
            "․",
        },
        style = {
            vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("Whitespace")), "fg", "gui"),
        },
        exclude_filetype = "...",
    },
}

example:

require('hlchunk').setup({
    indent = {
        chars = { "│", "¦", "┆", "┊", },

        style = {
            "#8B00FF",
        },
    },
})

command

this plugin provides some commands to switch plugin status, which are listed below

  • EnableHL
  • DisableHL

the two commands are used to switch the whole plugin status, when use DisableHL, include hl_chunk and hl_indent will be disable

  • DisableHLChunk
  • EnableHLChunk

the two will control hl_chunk

  • DisableHLIndent
  • EnableHLIndent

the two will control hl_indent

  • DisableHLLineNum
  • EnableHLLineNum

the two will control hl_line_num

  • DisableHLBlank
  • EnableHLBlank

the two will control hl_blank