Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

zig_fmt_autosave writes escape characters in the current buffer #105

Open

Description

@Gogopex

Heya,

~ ❱ nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1720049189
~ ❱ zig version
0.13.0

This is on a completely clean neovim and zig install. Entering :w with a Zig file opened causes escape characters to be printed in the current buffer. This happens across all the terminal emulators I use (ghostty, wezterm, alacritty).

Quick recording:
demo

The escape characters inserted:

]4;1;rgb:cc/24/1d��]4;2;rgb:98/97/1a��]4;3;rgb:d7/99/21��]4;4;rgb:45/85/88��]4;5;rgb:b1/62/86��]4;6;rgb:68/9d/6a��]11;rgb:1d/20/21��]10;rgb:eb/db/b2��]4;0;rgb:1d/20/21��]4;7;rgb:a8/99/84��]4;8;rgb:92/83/74��]4;9;rgb:fb/59/34��]4;10;rgb:b8/bb/26��]4;11;rgb:fa/bd/2f��]4;12;rgb:83/a5/98��]4;13;rgb:d3/86/9b��]4;14;rgb:8e/c0/7c��]4;15;rgb:eb/db/b2��]4;236;rgb:32/30/2f��]4;234;rgb:1d/20/21��]4;235;rgb:28/28/28��]4;237;rgb:3c/38/36��]4;239;rgb:50/49/45��]4;241;rgb:66/5c/54��]4;243;rgb:7c/6f/64��]4;244;rgb:92/83/74��]4;245;rgb:92/83/74��]4;228;rgb:f2/e5/bc��]4;230;rgb:f9/f5/d7��]4;229;rgb:fb/f1/c7��]4;223;rgb:eb/db/b2��]4;250;rgb:d5/c4/a1��]4;248;rgb:bd/ae/93��]4;246;rgb:a8/99/84��]4;167;rgb:fb/49/34��]4;142;rgb:b8/bb/26��]4;214;rgb:fa/bd/2f��]4;109;rgb:83/a5/98��]4;175;rgb:d3/86/9b��]4;108;rgb:8e/c0/7c��]4;208;rgb:fe/80/19��]4;88;rgb:9d/00/06��]4;100;rgb:79/74/0e��]4;136;rgb:b5/76/14��]4;24;rgb:07/66/78��]4;96;rgb:8f/3f/71��]4;66;rgb:42/7b/58��]4;130;rgb:af/3a/03�fn main() u8 {

I've tried tons of things to figure this out and ended up figuring out (after trying 100x things) that setting vim.g.zig_fmt_autosave = 0 fixed the issue, although obviously at the cost of the auto-formatting on save. I ended up trying to debug zig.vim and found that the "guilty" line is https://github.com/ziglang/zig.vim/blob/master/ftplugin/zig.vim#L41. However, my zig env's output seeems clear.

~ ❱ zig env
{
 "zig_exe": "/opt/homebrew/Cellar/zig/0.13.0/bin/zig",
 "lib_dir": "/opt/homebrew/Cellar/zig/0.13.0/lib/zig",
 "std_dir": "/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std",
 "global_cache_dir": "/Users/hey/.cache/zig",
 "version": "0.13.0",
 "target": "aarch64-macos.14.5...14.5-none",
 "env": {
  "ZIG_GLOBAL_CACHE_DIR": null,
  "ZIG_LOCAL_CACHE_DIR": null,
  "ZIG_LIB_DIR": null,
  "ZIG_LIBC": null,
  "ZIG_BUILD_RUNNER": null,
  "ZIG_VERBOSE_LINK": null,
  "ZIG_VERBOSE_CC": null,
  "ZIG_BTRFS_WORKAROUND": null,
  "ZIG_DEBUG_CMD": null,
  "CC": null,
  "NO_COLOR": null,
  "CLICOLOR_FORCE": null,
  "XDG_CACHE_HOME": null,
  "HOME": "/Users/hey"
 }
}

Has anyone had that issue? Am I going crazy?

Activity

  1. melenaus commented on Jul 27, 2024

    @melenaus

    I have the same issue.
    After deleting all nvim chaches and re-installing it works for a short time before zig fmt starts throwing errors and slowing down massively on save. This happens both on windows 11 and ubuntu.

  2. Gogopex commented on Jul 27, 2024

    @Gogopex
    Author

    I fixed it locally by modifying zig.vim, but not sure if it's good enough to merge. I can open up the PR if anyone's interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions