Skip to content

Files

203 lines (158 loc) · 4.54 KB

README.md

File metadata and controls

203 lines (158 loc) · 4.54 KB

Highlight Whitespace

Highlight unwanted whitespace across you project files. The fun part is that you can come up with your own palette of colors used for a specific pattern per a filetype!


Почитать на русском 🇷🇺

demo

Go to the Current Colorscheme section to see what each color stands for.
(Unfortunately placing it here breaks syntax highlighting for all multi-line code blocks below it)

Installation

With lazy.nvim

{
  "lukoshkin/highlight-whitespace",
  config=true,
}

With packer.nvim

use "lukoshkin/highlight-whitespace"

Customization

tws keyword - "main" pattern for trailing whitespace highlighting
clear_on_bufleave - boolean opt to clear highlighting in the current buffer before switching to another

lazy.nvim
{
  "lukoshkin/highlight-whitespace",
  opts = {
    tws = "\\s\\+$",
    clear_on_bufleave = false,
    palette = {
      markdown = {
        tws = 'RosyBrown',
        ['\\S\\@<=\\s\\(\\.\\|,\\)\\@='] = 'CadetBlue3',
        ['\\S\\@<= \\{2,\\}\\S\\@='] = 'SkyBlue1',
        ['\\t\\+'] = 'plum4',
      },
      other = {
        tws = 'PaleVioletRed',
        ['\\S\\@<=\\s,\\@='] = 'coral1',
        ['\\S\\@<=\\(#\\|--\\)\\@<! \\{2,3\\}\\S\\@=\\(#\\|--\\)\\@!'] = 'LightGoldenrod3',
        ['\\(#\\|--\\)\\@<= \\{2,\\}\\S\\@='] = '#3B3B3B',
        ['\\S\\@<= \\{3,\\}\\(#\\|--\\)\\@='] = '#3B3B3B',
        ['\\t\\+'] = 'plum4',
      }
    }
  }
}
packer.nvim
use {
  'lukoshkin/highlight-whitespace',
  config = function ()
    require'highlight-whitespace'.setup {
      tws = '\\s\\+$',
      clear_on_bufleave = false,
      palette = {
        markdown = {
          tws = 'RosyBrown',
          ['\\S\\@<=\\s\\(\\.\\|,\\)\\@='] = 'CadetBlue3',
          ['\\S\\@<= \\{2,\\}\\S\\@='] = 'SkyBlue1',
          ['\\t\\+'] = 'plum4',
        },
        other = {
          tws = 'PaleVioletRed',
          ['\\S\\@<=\\s,\\@='] = 'coral1',
          ['\\S\\@<=\\(#\\|--\\)\\@<! \\{2,3\\}\\S\\@=\\(#\\|--\\)\\@!'] = 'LightGoldenrod3',
          ['\\(#\\|--\\)\\@<= \\{2,\\}\\S\\@='] = '#3B3B3B',
          ['\\S\\@<= \\{3,\\}\\(#\\|--\\)\\@='] = '#3B3B3B',
          ['\\t\\+'] = 'plum4',
        }
      }
    }
  end
}

Ignoring filetypes

Ignoring specific filetypes is possible by setting an empty table next to a filetype in the palette.

To highlight only python and markdown filetypes

      palette = {
        python = {
          -- some patterns
        },
        markdown = {
          -- some patterns
        },
        other = {},
      }

To ignore highlighting only in javascript

      palette = {
        javascript = {},
        other = {
          -- some patterns
        },
      }

Current Colorscheme

This section refers to the GIF at the README beginning


r e d  color ─ trailing whitespace in Python (other than md)

d a r k   g r a y  ─ leading and trailing whitespace in comment sections

b r o w n  ─ in markdown


y e l l o w  color ─ redundant (multiple) spaces in Python

b l u e  ─ in markdown


o r a n g e  color ─ a space before a comma in Python

" g r e e n "  ─ in markdown


p u r p l e  color ─ tab indents instead of spaces