m00qek
baleia.nvim
Lua

Colorize text with ANSI escape sequences (8, 16, 256 or TrueColor)

Last updated Jul 8, 2026
202
Stars
13
Forks
6
Issues
+2
Stars/day
Attention Score
73
Language breakdown
Lua 97.6%
Shell 1.5%
Makefile 0.9%
โ–ธ Files click to expand
README

baleia.nvim

[![Integration][integration-badge]][integration-runs]

Colorize text with ANSI escape sequences (8, 16, 256 or TrueColor).

Requirements: Neovim 0.9.0 or higher.

image

Install

Using lazy.nvim:

{
  "m00qek/baleia.nvim",
  version = "*",
  config = function()
    vim.g.baleia = require("baleia").setup({ })

-- Command to colorize the current buffer vim.api.nvimcreateuser_command("BaleiaColorize", function() vim.g.baleia.once(vim.api.nvimgetcurrent_buf()) end, { bang = true })

-- Command to show logs vim.api.nvimcreateuser_command("BaleiaLogs", vim.cmd.messages, { bang = true }) end, }

Usage & Configuration

Baleia exposes functions to colorize buffers. You can use them manually (commands) or automatically (autocmds).

1. Manual Colorization

The setup above creates a :BaleiaColorize command. Use this when you open a file with ANSI codes (like a log file) and want to colorize it once.

vim.g.baleia.once(vim.api.nvimgetcurrent_buf())

2. Automatic Colorization (Tailing Logs)

To automatically colorize lines as they are appended to a buffer (e.g., when tailing a log file), use baleia.automatically.

Example: Colorize all .log files:

vim.api.nvimcreateautocmd({ "BufWinEnter" }, {
  pattern = "*.log",
  callback = function()
    vim.g.baleia.automatically(vim.api.nvimgetcurrent_buf())
  end,
})

Example: Colorize Quickfix Window:

vim.api.nvimcreateautocmd({ "BufReadPost" }, {
  pattern = "quickfix",
  callback = function()
    vim.g.baleia.automatically(vim.api.nvimgetcurrent_buf())
  end,
})

Setup Options

Pass these options to require("baleia").setup({...}):

| option | default value | description | | -----------------| --------------- | --------------------------------------------------------- | | name | "BaleiaColors" | prefix used to name highlight groups | | stripansicodes | true | remove ANSI color codes from text | | linestartsat | 1 (one-indexed) | at which column start colorizing | | colors | NR8 | table mapping 256 color codes to vim colors | | async | true | highlight asynchronously | | chunk_size | 500 | number of lines to process per loop iteration (async) |

With Conjure

This can be used to colorize [Conjure][conjure] log buffer. To do it you must tell conjure to not strip ANSI escape codes:

{
  "m00qek/baleia.nvim",
  version = "*",
  config = function()
    vim.g.conjurebaleia = require("baleia").setup({ linestarts_at = 3 })

local augroup = vim.api.nvimcreateaugroup("ConjureBaleia", { clear = true })

vim.api.nvimcreateuser_command("BaleiaColorize", function() vim.g.conjurebaleia.once(vim.api.nvimgetcurrentbuf()) end, { bang = true })

vim.api.nvimcreateuser_command("BaleiaLogs", vim.cmd.messages, { bang = true }) end, }, { "Olical/conjure", ft = { "clojure", "fennel" }, config = function() require("conjure.main").main() require("conjure.mapping")["on-filetype"]() end, init = function() -- Print color codes if baleia.nvim is available local colorize = require("lazyvim.util").has("baleia.nvim") vim.g["conjure#log#stripansiescapesequencesline_limit"] = colorize and 1 or nil

-- Disable diagnostics in log buffer and colorize it vim.api.nvimcreateautocmd({ "BufWinEnter" }, { pattern = "conjure-log-*", callback = function() local buffer = vim.api.nvimgetcurrent_buf() vim.diagnostic.enable(false, { bufnr = buffer }) if colorize and vim.g.conjure_baleia then vim.g.conjure_baleia.automatically(buffer) end end, }) end, },

Developer API

baleia provides two functions, bufsetlines and bufsettext, that have the same interface as the default vim.api.nvimbufset_lines and vim.api.nvimbutset_text. Using those is very efficient because they do all color detection and ANSI code stripping before writing anything to the buffer.

local new_lines = { '\x1b[32mHello \x1b[33mworld!' }

-- appending using Neovim standard API local lastline = vim.api.nvimbufline_count(0) vim.api.nvimbufsetlines(0, lastline, lastline, true, newlines)

-- appending using Baleia API local lastline = vim.api.nvimbufline_count(0) local baleia = require('baleia').setup { } baleia.bufsetlines(0, lastline, lastline, true, new_lines)

[integration-badge]: https://github.com/m00qek/baleia.nvim/actions/workflows/integration.yml/badge.svg [integration-runs]: https://github.com/m00qek/baleia.nvim/actions/workflows/integration.yml [conjure]: https://github.com/Olical/conjure

License

MIT

๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท m00qek/baleia.nvim ยท Updated daily from GitHub