On 2021-04-02, Peng Yu wrote:
> > According to the shfmt project page,
https://github.com/mvdan/sh,
> > someone has written a Vim plugin for shfmt,
> >
https://github.com/z0mbix/vim-shfmt. You may want to check that
> > out, too.
>
> This probably is a better approach. I am trying to set it up. I use
> pathogen. So I set it up like this.
>
> ~/.vim$ ls -dlgG bundle-available/vim-shfmt
> drwxr-xr-x 7 224 2021/04/02-19:51:21 bundle-available/vim-shfmt
> ~/.vim$ ls -dlgG bundle/vim-shfmt
> lrwxr-xr-x 1 29 2021/04/02-19:52:09 bundle/vim-shfmt ->
> ../bundle-available/vim-shfmt
>
> It is not clear to me what instructions on
>
https://github.com/z0mbix/vim-shfmt I need to following, as its author
> does not assume users use pathogen. Do you know?
I'm afraid I'm of no help with that. I don't use Plug, pathogen or
shfmt. For a simple plugin like this one, I just copy the files
into ~/.vim/autoload and ~/.vim/plugin.
>
https://github.com/z0mbix/vim-shfmt
>
> As of now, when I try `:Shfmt -p`, vim shows this error.
>
> Error detected while processing function shfmt#shfmt:
> line 11:
> Shfmt returned an error (often due to wrong syntax). Undoing changes.
> 9 more lines; before #1 0 seconds ago
For that, I would just look at the 11th line of shfmt#shfmt() and
see what the problem might be. I just did. It's in
autoload/shfmt.vim. That message is displayed when a shell error
results from passing a set of lines to the shfmt command with the
options you specify. Unfortunately, that command is preceded by
:silent so we can't see what the error was.
There are lots of ways to troubleshoot this. One way would be to
execute your command with :debug, like this:
:debug Shfmt -p
Then single step (using the s debug command) to line 9 of the
shfmt#shfmt() function. (It's a short function, so this won't be
hard.) As you execute that line, Vim will show you the command
being executed, with the variables expanded.
If that command looks OK to you but it still generates an error,
then you can try executing it from the Vim command line and see what
error message is displayed by shfmt. That may tell you what the
problem is.
If you're still having problems, post here what you've discovered.
Remember that I don't have shfmt installed so I won't be able to try
your examples.
Regards,
Gary