mkdir -p ~/.vim/pack/plugins/start/
cd ~/.vim/pack/plugins/start/
git clone https://github.com/ziglang/zig.vim
All done.
Okay I now have files in my $HOME, in the relevant directories. That’s nice. But the readme appears to have no next step. How do I activate it? How do I use it? What does it do? What’s the next step?
Any help would be appreciated.
Thanks Muchly.
What I have done to fix this myself
So I zig init a fresh project and make a complete pigs ear of the default main.zig. Every style crime I can think of has been put into it. Vim opens and close it fine. No reformatting as far as I can see.
Read the README.md - nothing about a next step or how to use it.
Random commands in the hopes that something happens. Nothing happens.
:indent
:fmt
:run
:zig
:zig fmt
Am I running vim > 8? Yes I am.
$ vi -version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 04 2023 10:24:44)
Garbage after option argument: "-version"
More info with: "vim -h"
This plugin enables automatic code formatting on save by default using zig fmt. To disable it, you can use this configuration in vimrc:
For anyone who is interested here is my .vimrc
Which works fine with zig.vim
cat .vimrc
unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim
"REM mapping "adding a rem for a paragraph" \r "deleting a rem for a paragraph" \rx
map <leader>r :norm 0i//<enter>
map <leader>rx :s/\/\///<enter>
"REM mapping to get a shortcut to vim expand
map <leader>e 0v$:!~/vim_expander/vim_expander<enter>
"REM add 4 spaces and removbe 4 spaces, from the start of the line
map <leader>s :norm 04i<Space><Esc>
map <leader>sx :norm 04x<Enter>
"REM set relative numbering for precise j and k jumps
set relativenumber
set number
"REM mapping to turn off relativenumber, helpfull for copy and paste
map <leader>q :set norelativenumber<Enter>:set nonumber<Enter>
"REM Disable annoying beeping
set noerrorbells
set vb t_vb=
"REM turn syntax on
syntax on
"REM stop ~ files appearing?
set nobackup
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
it will
Tabs become 4 spaces
relative numbers down the side
\q gets rid of the relative numbers down the side if I want to copy and paste
turn off the error bells
if you “vip” a block ie visually highlight them
\r will add a rem to each line ie \
\rx will delete the rem on each line
\s will add 4 spaces to each line
\sx will delete 4 spaces from each line
vim_expander is zig code that will box text in vim and block format zig code.
Clearly I am in the pit of despair. Where everything I do makes the problem worse. I am seriously considering a complete re install of the entire os. It’s the only way to be sure.
I am trying to destroy, with extreme prejudiced this vi fmt thing. Despite destroying everything. Even creating a new user and new home. I get the following error when :w . But only with .zig files. .txt is just fine.
Error detected while processing BufWrite Autocommands for "<buffer=1>":
"test.zig" [New] 0L, 0B written
Press ENTER or type command to continue
There is more, but it gets overwritten on the screen so I cannot copy and paste.
It’s something along the line of.
unknownfunction zig#fmt#format
Any hints ? I just want to go back to before this nightmare started. Sorry for my tone. I have just run out of hair to pull out.
Clearly this is a skill issue on my behalf. But in my defense I don’t want to be a vim guru. I just want to use it, not master it.
My solution was to
Reinstall the fmt software
mkdir -p ~/.vim/pack/plugins/start/
cd ~/.vim/pack/plugins/start/
git clone https://github.com/ziglang/zig.vim
This gets rid of the error. To disable fmt I then added the following to my .vimrc
" unrem to run the defaults which do not run if you have am .vimrc. see vim -V
"unlet! skip_defaults_vim
"source $VIMRUNTIME/defaults.vim
" Turn off the zig fmt
let g:zig_fmt_autosave = 0
The long view
The fact I could not backout this change bothers me. The solution appears to be use
nixos at https://nixos.org/. This os allows you to quickly reinstall as it has “Declarative builds and deployments.”
Does anyone use this distro in the zig community and if so, is it any good? Does it live up to it’s hype?
I am currently not using NixOS, but I have a question: what distro are you using right now?
I used Vim in the past, but right now I use NeoVim and the Zig language server from nvim-lspconfig. It also does format on save you can get auto-completion (if you either go the hard way and configure nvim-cmp manually or if you just use some starter template, there are many).
My Zig rig is running dual boot from the Bios. One side is standalone Debian 12 and the other is qubes/debian. The problem occurred in my standalone Debian 12 setup with gnome. It’s a fairly basic install. The idea is that if I have a problem on the qubes side, I can rule out any qubes problem, if I can reproduce it on the Debian standalone side.
I did look at neovim. I Installed it. Then installed all the addons. It was just too much. Too soon. I like slow incremental change. One step at a time. So I can get used to it and roll back if necessary. In short, I like to be in charge. In control. So I went back to safe vim. The vim fmt plug in was my next attempt at a non vanilla setup. It was a disaster. And still is.
Despite the plug in being deactivated with
let g:zig_fmt_autosave = 0
It still not right. But it’s livable until I do my next reinstall. I am not happy with debian/gnome and qubes is too slow. So I was looking at the next bigger better more distro. Just wondered if anyone had tried nixos with it’s roll back facility.
I am not a total monk on vim. I have installed my own “plug in” using zig. After all why use neovim/ lua, when you can use vim/zig? Nothing exciting yet, but it turns out that vim, out of the box, can send output to a standalone executable and receive input in return.
If I type
Box This is a big title \e
The line above is replaced with
////////////////////////////////////////////////////////////////////////////////
// //
// This is a big title //
// //
////////////////////////////////////////////////////////////////////////////////
the “cow” command is just a file called cow.dat which that the zig code finds and expands.
The file have variables like ${1} ${2} ${“4”) which are replaced. So in this case the ${1} is replaced with “hello samuel-fiedler” ie
And there are many more files. Most of which are much more boring.
However the “delete_this /e” always makes me smile. When I come across it in my zig code.