I want vim to tell me (only when I ask it to) if there are variables not used in the current file.

Is this possible given that for now I need it in my javascript/php projects?

1 Answer 1


I do not work in PHP but the following instructions for JavaScript are still relevant.

What you want is a linter: this is an external software analysing statically you code. For JavaScript, I advise you to use JSLint. JSLint is far to be permissive, you should see how to configure it (basically, you just have to put a comment on top of your JavaScript file). I use this configuration:

/*jslint todo: true, browser: true, continue: true, white: true*/

Assuming you are using Linux, you could install (globally) JSLint on your computer using npm.

Now you need to use it in Vim, for that there are plugins. The simplest way I know is to use Syntastic. Syntastic is a plugin for checking error (when you save the file) on the current file using an external program.

If you have installed JSLint globally, Syntastic would automatically works with your JavaScript files. Note that Syntastic works on Vim 7.4 so there is no asynchronous operation (when you save the file, you have to wait that Syntastic finishes its job).

In a nutshell:

  • Use a linter to find the unused variables (example: JSLint)
  • Use a plugin that calls linters and compilers for checking errors (example: Syntastic or YouCompleteme with a good dose of despair when configuring it). Or you could see how to do it yourself (start by reading :h errorformat).

PS: You asked to highlight the variables. With the solution I proposed you, it will not highlight the variables but show the line where errors are present (and the reason of the error).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.