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?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI 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:
: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).