feat(vim): split out and refactor format on save so it can be toggled

This is off by default and will need to be turned on when developing on
code that will need to be formatted on saving.
This commit is contained in:
Ade Attwood 2022-11-15 20:05:39 +00:00
parent e7897fc7e0
commit 0506dd4842
2 changed files with 17 additions and 5 deletions

View file

@ -75,8 +75,3 @@ let g:CommandTWildIgnore="*/node_modules/*,*/vendor/*,*/runtime/*,*/public_html/
" Required for complietion with nvim-cmp
set completeopt=menu,menuone,noselect
" Format code on save
augroup fmt
autocmd!
autocmd BufWritePre * undojoin | Neoformat
augroup END

View file

@ -0,0 +1,17 @@
"
" Functions to toggle format on save with Neoformat. This is off by default so
" I don't accidentally start formatting when rebasing (bad memories).
function s:fmt_on_save_enable()
augroup aa_fmt
autocmd!
autocmd BufWritePre * undojoin | Neoformat
augroup END
endfunction
function s:fmt_on_save_disable()
autocmd! aa_fmt
endfunction
command! FMTOnSaveEnable call s:fmt_on_save_enable()
command! FMTOnSaveDisable call s:fmt_on_save_disable()