On 4/2/21, 'Grant Taylor' via vim_use <vim_use@googlegroups.com> wrote: > On 4/2/21 3:52 PM, Peng Yu wrote: >> I want to use shfmt to indent bash script in vim instead of using the >> default vim indenter. Could anybody show me how to set this up in vim? > > I would play with the formatprg setting. > > :help formatprg > >> shfmt -l -w script.sh > > Based on my read of the help section, it looks like formatprg expects to > read STDIN and write to STDOUT. So you might need some sort of wrapper > to read Vim's STDOUT to a file, shfmt said file, then write said file > back to Vim's STDIN.
It can take the file from STDIN in this way. The output is to STDOUT. shfmt /dev/stdin < script.sh Could you show me the commands (that can be put in ~/.vimrc) to set formatprg to `shfmt /dev/stdin` just for a file when it is determined as a bash script? I don't want to mess it up for other file types. > > But I suspect that this is eminently doable. > > > > -- > Grant. . . . > unix || die > > -- > -- > You received this message from the "vim_use" maillist. > Do not top-post! Type your reply below the text you are replying to. > For more information, visit http://www.vim.org/maillist.php > > --- > You received this message because you are subscribed to a topic in the > Google Groups "vim_use" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/vim_use/D1sH4gr3LZA/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > vim_use+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/vim_use/ed861df1-0a61-cae5-dfd9-8c576d664e92%40spamtrap.tnetconsulting.net. > -- Regards, Peng -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CABrM6w%3DsqwwBBgOavf_Ns7bDfJi%3D2B0CWcovOVE31_Myo_iCYg%40mail.gmail.com.