tags:

views:

218

answers:

4

Lately I've been making a couple of mistakes when refactoring in Vim, the result was undefined and unused variables. Any decent IDE (like NetBeans) would mark them as such, but I've yet to come across a Vim plugin that does the same.

Can anyone help me out? I'm mainly programming in PHP.

A: 

There should be a solution with the Syntastic plugin, on which you would need to put a PHP static code analyzer like PHPLint.

However I never spent some time to test this !

Other PHP programs can be found on this SO answer.

Drasill
I've been looking into Syntastic, let's see what I can come up with... Thanks for the links!
pestaa
A: 

When renaming vars in a whole file type in vi cmd line:

:%s/\$oldName/\$newName/

When renaming the between line 14 and 21 (e.g inside a function) type

:14,21s/\$oldName/\$newName/

When renaming vars recursively in a directory type in vi cmd line:

:!find DIRECTORY_PATH -name "*.php" | xargs sed -ni 's/\$oldName/\$newName/'

Make a backup of the folder before to avoid headaches. ;)

thorsten
His question was not about refactoring, I think, but about detecting mistakes like undefined variables.
Drasill
Instead of making backup always keep it under version control. Besides that the answer doesn't relate to the question.
Adam Byrtek
+1  A: 

Well, this might not be what you are looking for, but if you must have Vim keybindings (I know I need them), then jVi brings this to NetBeans. I don't know if this is a viable option for you, but maybe this will help.

David Hollman
Tried it, it gives me almost zero power of the original platform. Thanks anyway.
pestaa
That's interesting. How long ago did you try it? I have yet to come across a feature in Vim that I use on a reasonably frequent basis that isn't implemented in jVi. You must be a true Vim power user. Anyway, like I said, it's probably not what you're looking for.
David Hollman
It was like a year ago. jVi implements basic editing bindings only, which is nice, but I'd miss the plugins, the buffers, location lists, configurable statusbar and tight integration with the command line. Just to name a few. I recommend you to try out Vim outside Netbeans and discover its confusingly endless possibilities.
pestaa
@pestaa: I agree with your statement that Vim on the command line has "confusingly endless possibilities." And I do use Vim when I'm working with Perl, bash scripting, and LaTeX, just to name a few. But jVi _does_ have buffers and location lists (and even :jumps) I agree that some plug-in support would be a great addition to jVi. I guess it comes down to what you really need in an editor and what you really need in a IDE, and what you're willing to give up on both sides. For instance, XCode is a better IDE for most of the stuff I do, but the lack of vim bindings was a deal breaker for me.
David Hollman
@David Hollman Thanks for the heads up! Nice to know jVi is better than I recalled. However, in the very long term, I rather place my bet on a whole platform than a Netbeans plugin. Without Vim, I would feel naked. Even raped. :) +1 for the informative conversation.
pestaa
+1  A: 

You can run Zend's PHP code analyzer from within VIM. I currently do this. The catch is that Zend Code Analyzer is no longer packaged as a separate binary when installing Zend Studio. I'm not sure which OS you are running. I'm running on OS X. If you don't already have the binary, use steps 1 & 2 on this site to get it - http://michalf.me/blog:zend-code-analyzer-in-textmate. You may have to adjust for your OS.

After getting the binary add the following to your .vimrc and replace the /usr/local/... with the path to your ZendCodeAnalyzer.

if !exists("autocommands_loaded")

  let autocommands_loaded = 1
  "PHP Make 
  autocmd BufRead *.inc,*.php set makeprg=/usr/local/bin/ZendCodeAnalyzer\ %
  autocmd BufRead *.inc,*.php set errorformat=%f(line\ %l):\ %m

endif

map <F7> :silent lmake<cr>:lwindow <cr>:redraw!<cr>

Now when you enter F7 it will run make which is set to run the ZendCodeAnalyzer. It will put the results into a location list - :help location. You can scroll through the location list and hit enter on a line and it will take you to that line in your file. If it doesn't find anything, then it won't open anything.

Brian