Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use quickfix in Vim to debug Bash scripts

I use Vim every day to write shell scripts. I have been reading about the quickfix window, and I think it could speed up my productivity in the edit-run-fix cycle.

If I understood properly, I have to write my own errorformat function in order to Vim to be able to catch the errors and introduce them into the quickfix window. But this seems to be really complicated.

Is there an easier/more convenient way to take advantage of the quickfix window in Vim when writing Bash scripts?

like image 720
Pythonist Avatar asked May 18 '14 19:05

Pythonist


People also ask

Is vim a bash?

bash-support is a highly-customizable vim plug-in, which allows you to insert: file headers, complete statements, comments, functions, and code snippets. It also enables you to perform syntax checking, make a script executable, start a debugger simply with a keystroke; do all this without closing the editor.


1 Answers

Vim's quickfix window is designed to speed up the edit-compile-edit cycle. Since Bash scripts do not get compiled, we have to substitute something else for that step that can point out errors in the current script.

What you want is a static analysis tool for Bash scripts. There are two good ones: shellcheck and checkbashisms. You'll want to install at least shellcheck, as it's the more comprehensive of the pair, but installing checkbashisms will help catch a few more issues.

To integrate those two tools into Vim, you need a plugin called Syntastic. Check the project page for installation instructions.

Once you've got everything installed, you'll be able to get immediate feedback on basic issues in your Bash script:

Vim window with Syntastic + shellcheck

  • Use :SyntasticCheck to force the checker to run
  • If you want the "quickfix" window to appear, run :Errors
like image 134
Michael Kropat Avatar answered Sep 19 '22 09:09

Michael Kropat