diff --git a/README.md b/README.md index 2286101..e0e7f88 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,14 @@ This plugin enables automatic code formatting on save by default using let g:zig_fmt_autosave = 0 ``` +If `zig fmt` encounters a code formatting error, this plugin populates +the location list with relevant errors. To disable automatically switching +to the location list, use this configuration in vimrc: + +``` +let g:zig_fmt_autoswitch = 0 +``` + The default compiler which gets used by `:make` (`:help :compiler` for details) is `zig_build` and it runs `zig build`. The other options are: * `:compiler zig_test` which runs `zig test` on the current file. diff --git a/autoload/zig/fmt.vim b/autoload/zig/fmt.vim index e1c6bba..8bf93e9 100644 --- a/autoload/zig/fmt.vim +++ b/autoload/zig/fmt.vim @@ -69,7 +69,12 @@ function! zig#fmt#Format() abort if err != 0 echohl Error | echomsg "zig fmt returned error" | echohl None - return + if get(g:, 'zig_fmt_autoswitch', 1) + return + else + wincmd p + return + endif endif " Run the syntax highlighter on the updated content and recompute the folds if