13

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.

Idan K
  • 20,443
  • 10
  • 63
  • 83
pestaa
  • 4,749
  • 2
  • 23
  • 32
  • 2
    Vim doesn't usually include those sorts of features as they take a fair bit of CPU to check the code, and PHP is a dynamic language which makes it even more difficult. – too much php Sep 07 '10 at 23:04
  • I did realize Vim has better capabilities in other areas, but given the resources we can throw at checking even dynamic scripts nowadays made me want a little more interactive coding, if you know what I mean. – pestaa Sep 08 '10 at 09:30

5 Answers5

3

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.

Community
  • 1
  • 1
Drasill
  • 3,917
  • 29
  • 30
  • I've been looking into Syntastic, let's see what I can come up with... Thanks for the links! – pestaa Sep 08 '10 at 09:32
1

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.

Daisy Sophia Hollman
  • 6,046
  • 6
  • 24
  • 35
  • Tried it, it gives me almost zero power of the original platform. Thanks anyway. – pestaa Sep 14 '10 at 09:12
  • 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. – Daisy Sophia Hollman Sep 14 '10 at 13:28
  • 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 Oct 12 '10 at 05:56
  • @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. – Daisy Sophia Hollman Oct 13 '10 at 13:22
  • 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 Oct 14 '10 at 17:52
1

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
  • 3,571
  • 7
  • 44
  • 70
0

I'm not sure how intelligent this plugin is but it seems to do what you want: https://github.com/vim-scripts/php_localvarcheck.vim

Marlun
  • 1,543
  • 3
  • 12
  • 14
0

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. ;)

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • His question was not about refactoring, I think, but about detecting mistakes like undefined variables. – Drasill Sep 10 '10 at 09:55
  • Instead of making backup always keep it under version control. Besides that the answer doesn't relate to the question. – Adam Byrtek Sep 19 '10 at 22:43