refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / vim-shfmt / README.md
1 ---
2 title: vim-shfmt
3 homepage: https://github.com/z0mbix/vim-shfmt
4 tagline: |
5   vim-shfmt: a vim plugin for shfmt
6 ---
7
8 To update (replacing the current version) run `webi vim-shfmt`.
9
10 ## Cheat Sheet
11
12 `vim-shfmt` uses [shfmt](https://webinstall.dev/shfmt) to format your `bash`
13 scripts on save.
14
15 Use `:Shfmt` to run manually (or just save the file with `:w`).
16
17 This plugin comes with reasonable defaults, which install to
18 `~/vim/plugins/shfmt.vim`:
19
20 ```vim
21 let g:shfmt_extra_args = '-i 4 -sr -ci -s'
22 let g:shfmt_fmt_on_save = 1
23 ```
24
25 ### How to install and configure manually
26
27 1. Clone `vim-shfmt` into your `~/.vim/pack/plugins/start`:
28
29    ```bash
30    mkdir -p ~/.vim/pack/plugins/start/
31    git clone --depth=1 https://github.com/CHANGEME/EXAMPLE.git ~/.vim/pack/plugins/start/shfmt
32    ```
33
34 2. Create the file `~/.vim/plugins/shfmt.vim`. Add the same contents as
35    <https://github.com/webinstall/webi-installers/blob/master/vim-shfmt/shfmt.vim>,
36    which will look something like this:
37
38    ```vim
39    " ~/.vim/plugins/shfmt.vim
40
41    " 4 indents, space between redirects, indented case statements, simplify
42    let g:shfmt_extra_args = '-i 4 -sr -ci -s'
43    let g:shfmt_fmt_on_save = 1
44
45    " auto run on .sh and .bash files
46    augroup LocalShell
47        autocmd!
48
49        autocmd BufWritePre *.sh,*.bash Shfmt
50    augroup END
51    ```
52
53 3. Update `~/.vimrc` to source that plugin:
54    ```vim
55    " shfmt: reasonable defaults from webinstall.dev/vim-shfmt
56    source ~/.vim/plugins/shfmt.vim
57    ```