nvim ASCII color
目录
Baleia Auto-Colorize for Neovim
Problem
Auto-run baleia.nvim to colorize ANSI escape codes when opening, reloading, or creating .log files.
Key Gotchas
-
lazy.nvim race condition — Don’t use a separate autocmd that depends on
vim.g.baleiabefore the plugin loads. Instead, use lazy.nvim’s built-ineventpattern matching to trigger loading, then handle the buffer insideconfig. -
automatically()vsonce()— They do different things:once(buf)— colorizes existing buffer content immediately.automatically(buf)— attaches annvim_buf_attachhandler for future lines only; does NOT touch current content.
-
Reloads (
:e,:e!) —configonly runs once. You need aBufReadPostautocmd to re-colorize on reload. -
automatically()is idempotent — it checks abaleia_on_new_linesbuffer var and skips if already attached. Safe to call multiple times.
Solution
All logic lives in the plugin spec — no separate autocmd files needed.
|
|
How Each Scenario Works
| Scenario | What fires | once |
automatically |
|---|---|---|---|
First open .log |
Explicit call in config |
Colorizes existing ANSI | Attaches buf handler |
Reload (:e!) |
BufReadPost autocmd |
Re-colorizes reloaded content | No-op (already attached) |
Open another .log |
BufReadPost autocmd |
Colorizes existing ANSI | Attaches buf handler |
Create new .log |
BufNewFile autocmd |
No-op (empty buffer) | Attaches buf handler |
Notes
- For
tail -f/ live-log scenarios,automaticallyensures newly appended lines are colorized as they arrive. - Remove the
BufReadPost quickfixentry from the event list if you don’t need quickfix colorization. - Tested on baleia.nvim v1.x (
m00qek/baleia.nvim).
相关内容
支付宝
微信

william