Home

Awesome

<h1 align='center'> deadcolumn.nvim </h1>

luarocks

<p align='center'> <b>Don't across that column in Neovim</b> </p> <p align='center'> <img src=https://user-images.githubusercontent.com/76579810/227669246-1cb53d93-1a8b-4edd-949e-9e6da6fa698b.gif width=90%> </p>

Deadcolumn is a neovim plugin to assist users in maintaining a specific column width in their code. This plugin operates by gradually displaying the colorcolumn as the user approaches it. It is useful for people who wish to keep their code aligned within a specific column range.

Table of Contents

Features

Installation

Options

:warning: Notice

You don't need to call the setup() function if you don't want to change the default options, the plugin should work out of the box if you set colorcolumn to a value greater than 0.

The following is the default options, you can pass a table to the setup() function to override the default options.

local opts = {
    scope = 'line', ---@type string|fun(): integer
    ---@type string[]|fun(mode: string): boolean
    modes = function(mode)
        return mode:find('^[ictRss\x13]') ~= nil
    end,
    blending = {
        threshold = 0.75,
        colorcode = '#000000',
        hlgroup = { 'Normal', 'bg' },
    },
    warning = {
        alpha = 0.4,
        offset = 0,
        colorcode = '#FF0000',
        hlgroup = { 'Error', 'bg' },
    },
    extra = {
        ---@type string?
        follow_tw = nil,
    },
}

require('deadcolumn').setup(opts) -- Call the setup function

FAQ

Why can't I see the colored column?

This can have several reasons:

  1. If you are using the default config, it is expected that you can't see the colored column in normal mode, because the colored column is only shown in insert mode and replace mode by default. You can change the modes option to show the colored column in normal mode.

  2. Please make sure you have set colorcolumn to a value greater than 0 in your config. Also, make sure that you have termguicolors set using :set termguicolors

  3. If you set colorcolumn to a relative value (e.g. '-10'), make sure textwidth is set to a value greater than 0.

How to set different colorcolumn for different filetypes?

This plugin does not set colorcolumn for you, it only reads and uses the value of colorcolumn of the current buffer to show the colored column when needed.

It leaves to you to set colorcolumn for different filetypes, under different conditions, which is more flexible compared to setting colorcolumn in the plugin setup function.

There are mainly two ways to set colorcolumn for different filetypes:

  1. Using autocmd:

    You can use the autocmd command to set colorcolumn for different filetypes.

    For example, you can set colorcolumn to 80 for markdown files:

    autocmd FileType markdown setlocal colorcolumn=80
    
  2. Using ftplugin:

    You can also use the ftplugin directory to set colorcolumn for different filetypes.

    For example, you can create a file named markdown.vim in the ftplugin directory under your config directory, and set colorcolumn to 80 for markdown files:

    setlocal colorcolumn=80
    

Known Issues

Transparent Background

If you are using a transparent background, the colored column may not be displayed properly, since the background color of the colored column dynamically changed based on the blending of 'Normal' background color and the orignial 'ColorColumn' background color.

If Deadcolumn cannot find the 'Normal' background color, it will use '#000000' (pure black) as the default background color for blending.

There is no way to fix this, since terminal emulators do not support setting a transparent background color for a specific character.

Workarounds:

  1. You can set opts.threshold to 1 to disable blending when the length is smaller than colorcolumn and show the colored column only when it is greater than colorcolumn, OR

  2. You can assign a different highlight group or a fixed colorcode to be used for blending with the original 'ColorColumn' background color, for example:

    require('deadcolumn').setup({
        blending = {
            colorcode = '#1F2430',
            hlgroup = { 'NonText', 'bg' },
        },
    })
    

Similar Projects