From 3d2466581a921d3418671023f6cc0d8ab8db98fd Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 15 Oct 2018 11:34:06 +0200 Subject: [PATCH] Automatically execute shfmt on shell script save Signed-off-by: Knut Ahlers --- after/plugin/shfmt.vim | 10 ++++++++++ vimrc | 1 + 2 files changed, 11 insertions(+) create mode 100644 after/plugin/shfmt.vim diff --git a/after/plugin/shfmt.vim b/after/plugin/shfmt.vim new file mode 100644 index 0000000..46f0eec --- /dev/null +++ b/after/plugin/shfmt.vim @@ -0,0 +1,10 @@ +if exists('g:loaded_shfmt_wrapper') + finish +endif +let g:loaded_shfmt_wrapper = 1 + +function! SHFmt() + let save_pos = getpos(".") + execute "%!shfmt -s" + call setpos(".", save_pos) +endfunction diff --git a/vimrc b/vimrc index 9d2011c..fbd7962 100644 --- a/vimrc +++ b/vimrc @@ -1025,6 +1025,7 @@ let g:go_autodetect_gopath = 0 " au BufWritePre *.py,*.js :Autoformat +au FileType sh au BufWritePre :call SHFmt() " " Custom commands