Plugins to make PHP coding easier and efficient in (g)Vim?
e.g. Error detection/highlight, debugging, etc?
For error detection, there is no miracle, but Syntastic is a good start.
If you have installed xdebug, then you can use :
DBGp-client
vim-add-xdebug (I never used it, but seems more recent)
DBGPavim (the most recent, nice plugin with good documentation)
Also, there is a package with some PHP config/plugins all-in-one, PIV, but I prefer installing plugins one by one.
Finally, the best advice would be to first install Vundle, so that you can then do this :
:BundleSearch php
Then yank the plugins results you're interested in, into your .vimrc, then
:BundleInstall
And you can test these plugins in no time. And launch :BundleClean after removing lines in your .vimrc if you don't like the plugin.
I found the free book 'A Byte of Vim' very helpful. It contains descriptions of a useful set of plugins.
http://www.swaroopch.com/notes/Vim
See also Dr Chip's Vim page.
http://www.drchip.org/
Related
I know that \Phar and \PharData exist, but I'm having some trouble with the methods they supply so far. I'm still having to detect the mime-type / file type by whatever means, before determining which Phar*::method() to use in an attempt to extract the archive and do work on the files it contains.
Is there a go-to, "easy-button" class that I could include (maybe some package available via composer) that handles this at a very high level? Or am I failing to use the Phar and friends properly or in need of re-RTM so far?
Basically, I want to do the following (it's a CLI script that I control for now, so security, while important with this type of thing, is on the backburner for now):
Detect that a file might be an archive of some kind.
Validate that it seems to be one of the following: .tar, .gz, .tar.gz, or .zip.
If so, attempt to extract the archive and then parse the content of it's actual files.
Is there an "easy-button" for this that I'm unaware of, or do I need to build some logic that guesses as best it can as to what type of archive it might be, and then try to use the appropriate Phar* method to attempt to extract it's files and do whatever work I need to on them?
I hope that makes sense the way I wrote it. I'm trying to avoid re-inventing the wheel for a mini-project here if someone has already figured all of this out basically.
So, while continuing to research this I ended up seeing my own (this) SO question in google search results, which annoys me for some reason. So just in case someone stumbles upon this looking for a good solution, I've since found a couple by searching https://packagist.org/search/?q=archive (go figure):
Here's a few of them that seem promising.
wapmorgan/UnifiedArchive:
wapmorgan/UnifiedArchive (packagist)
wapmorgan/UnifiedArchive (github source)
Features (at first glance):
Only has one requirement of pear/archive_tar (which includes a few
more utility classes also from pear).
It attempts to detect the filetype for you, so it could eliminate the need to do that on your own.
alchemy/zippy:
alchemy/zippy (packagist)
alchemy-fr/Zippy (github source)
Features (at first glance):
Code looks to have been very well designed.
Seems to integrate with Laravel and guzzle\guzzle (the popular php http client) in some way so that might be an advantage for some.
zetacomponents/Archive
zetacomponents/Archive (packagist)
zetacomponents/Archive (github source)
Features (at first glance):
It seems to be a pure php implementation? If so that's just awesome.
Last updated 15 days ago, so it's the most active of the three I mentioned.
Seems to be maintained by an organization as opposed to a single person.
It has the most downloads by far on packagist (when searching for "archive"), and though I haven't played with it yet, that's usually a good sign.
Disclaimer: I have only actually tried wapmorgan/UnifiedArchive as of this writing, and so far it's exactly what I was looking for.
Anyway, I hope this helps anyone who might stumble upon this question.
If you don't need pure php and if your code is running on a linux machine, a
exec('uncompress [-cfv] [file...]');
or a
exec('unzip filename.zip -d destination');
will extract the file and make it usable for php.
Of course you need to check the extension (zip, tar, etc) in order to call the right command
As a disclaimer, I'm fairly new to Netbeans and wasn't sure exactly how to phrase this question.
I have two versions of the same application. The only difference is a few functions in several different files. Is there an option to remove tagged code folds on export? For example:
/* #Version2 Only */
function version2Function {
//code
}
Or is some kind of version control the best option? It's a real pain to go through and manually add these in with each update. Thanks for any help in advance.
I think you better use svn. And create the branch.
The one which we have been using is Git (as a version control) about annotations which gets added on the function, those are called 'docblocks'.
as far as I understand your question, you want to use version control system and want to know if there are any changes?
Once you use git and use netbeans with reference to that source, it lets you know of any changes by showing a color mark (like blue or green) on left panel, right next to line numbers...
You dont have to configure your netbeans for it.
So... use git on your code (Google for good tutorials) and get started... then, you do not have to worry about different versions :)
Hope this helps.
I know that it is possible to use Ctrl+] to jump to a definition in Vim and this can work in conjunction whith either ctags or Cscope. I am looking for a more accurate alternative to both ctags and Cscope when working PHP. Sometimes there are multiple possible results to choose from or false positives. I only want to jump to the actual definition of whatever is under the cursor. Ideally this should work for variables, functions, constants, and classes.
I don't see why this can't be done by analyzing the files. I have finally overcome just about every other annoyance/misunderstanding I have with Vim by learning and customizing, so if I could nail this one it would be awesome.
Also, do other's agree that Cscope and ctags are not accurate enough for PHP or am I doing something wrong?
UPDATE
4 years later, I am still using Vim with PHP, and still having this problem. I have tried eclim, ctags, exubarant-ctags, universal-ctags, and cscope. I have tried passing various arguments to these programs to get them to generate better tags. The experience is very poor for all of these options.
But I understand the problem much better now. There might be nothing wrong with the tags generated by these programs. The problem seems to be that when you press Ctrl + ] in Vim or Neovim, it just looks for a tag by that name. It is not looking at the context of the file you are editing to see which tag by that name it should use. It does not even understand what language you are editing, and look for tags from code in that language.
Is there a way to make vim search through the tags file more intelligently, based on the context, and then jump to the most likely location? You know, like what would happen inside a good IDE?
As a C++ developer I had similar issues for a long time. Until, that is, I reorganized my approach to using tag files under Vim a few years ago. The trick that made it work for me was to generate separate tag files for different slices of code: my project, various external code libraries, etc... I then had to set the 'tags' option to look for the files in a priority order, with my local code project files coming first and then working outward from there with the system header files being LAST.
In my case, I had separate tag files for each of these and listed in this order in the 'tags' option:
My local project
Any other project that this project uses
System-bundled libraries (boost)
System-bundled libraries (WxWidgets)
System libraries (C++ standard libraries)
System libraries (all else)
I'm not a PHP developer, but again the main mistake I made for a long time was just generating a single tags file FOR EVERYTHING. I'd have upwards of 30 tags to search through many times (using the :tag command). If you generate multiple tags files you have much more control over the search order of tags and thus what tags in which files are found.
See if that works for you. It did for me.
To improve ctags for PHP, you could create tags file like this:
#!/bin/bash
cd /path/to/framework/library
exec ctags-exuberant -f ~/.vim/mytags/framework \
-h ".php" -R \
--exclude="\.svn" \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cf \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'
then load the tags
:set tags=~/.vim/mytags/framework
taken from my blog post
You may also wanna take a look at eclim.
This could utilize eclipse's completion feature, and it should work fine for PHP (I haven't tried).
Struggled with the same problem for a long time until I found the LanguageServer for PHP.
It provides features like GoToDefinition, ShowReferences, Tags at current document etc. It is integrating okay with fzf right out of the box.
Things I don't like about it:
autocompletion is slow compared to other frameworks like padawan
it doesn't cache (yet) your project's index, which means, it has to reindex when you open neovim. Nevertheless, you can use the GoToDefinition functionality while it's still indexing.
Quick setup for vim-plug:
Plug 'autozimu/LanguageClient-neovim', { 'do': ':UpdateRemotePlugins' }
Plug 'roxma/LanguageServer-php-neovim', {'do': 'composer install && composer run-script parse-stubs'}
autocmd FileType php LanguageClientStart
nnoremap <silent> gd :call LanguageClient_textDocument_definition()<CR>
nnoremap <silent> gr :call LanguageClient_textDocument_references()<CR>
Best solution I've found so far.
More of a workaround, but if you press g CTRL+[ instead of just CTRL+', you get a list of all the tags of that name, and you can select which one to jump to.
PHP is not a well designed language, and it is not statically typed. As such, the foundation is just not there for any good tools of this kind to be made that would be practical to use in real world projects. IDEs, language servers, and Vim and Neovim plugins can only know as much about the code as the language allows. It is possible to write very consistent code in PHP with as much types as possible and that only utilizes a limited subset of the language, such that tools could understand it. However if your team is capable of writing that good of PHP code, they are good enough to rewrite the code in a more well designed language that can support even better tooling, something like Kotlin which also has great IDE support.
I'm a Web developer. I had been using a variety of editors and ide-s for web development(php, javascript,html,css) six months before I decided to learn a true editor and started using emacs. I learned all the basics, used the starter kit, practiced using buffer, windows etc..
I got a grip in 2 months. A month ago I started learning about vim and I found a lot of plugins to achieve the things I want. I'm finding to achieve the same effect in emacs you have to do a lot(for php/js/css/html editing).
Here are the list of things I'm finding hard. Note: These things are related when I'm editing php/html/css/js.
syntax hightlighting(php/smarty). -- the php major mode is too old and it always highlights html/smarty inside the php code incorrectly.
I love ido-mode but i couldn't find how to define a project and fuzzy match files inside the predefined directory
I can setup nerdtree plugin to get a quick overview pane on the left with the files I'm working on with vim. But configuring speedbar and source code browser in emacs is bit difficult.
Context aware completion I really don't know how to do that. I have seen something like that in clojure mode where it shows the definition of a method in the messages area.
Tags-generation: The tags generated with excrebant-ctags does not always work with php. In vim it is easy I can open a file containing the definition right under the cursor.
Manual lookup I want to lookup the manual for a particular word under the cursor without opening the browser (in the messages area(mini-buffer)).
I love ido mode and switching b/w files in tramp,buffers,local files using ido-mode.
Can anyone point me in the right direction? Do you use emacs for same kind of editing I do? What is your work flow?.
nxthml-mode is the ultimate mode for web development.
You can easily define a project in terms of its VCS or .dir-locals.el with find-file-in-project.
Fuzzy matching is called flex matching in ido. You can enable it with:
(setq ido-enable-flex-matching t)
I've never had any problems with ctags, manual lookup is trivial to implement...
Manual lookup I want to lookup the manual for a particular word
under the cursor without opening the browser. (in the messages area
(mini-buffer))
It sounds like you are after eldoc-mode support for PHP? (enable it on a lisp file to see example)
;; Major modes for other languages may use ElDoc by defining an
;; appropriate function as the buffer-local value of
;; `eldoc-documentation-function'.
A search for eldoc-documentation-function and PHP turns up this:
http://www.emacswiki.org/emacs/php-doc.el
I like Emacs for small projects and quick editing.
There are things like C-x ( to make a repeat-macro, delete-matching-lines, describe-function (...), apropos, the quick C-x 2 to split window, the warnings (text was edited elsewhere do you really want...) and the quick Lisp fix in .emacs that make me having an Emacs open at all times.
But for bigger projects, when you want to hover a keyword and have its definition, the call hierarchy, the updated syntax highlighting etc... Emacs is not enough for me. I use Eclipse (which is slow and not perfect anyway for C C++).
syntax hightlighting(php/smarty). -- the php major mode is too old and it always highlights html/smarty inside the php code incorrectly.
The simplest and best way to manage mixed languages in one single buffer is to clone the window showing it with C-x 4 c and use different major modes for each window showing this single buffer, for example, one window with the php-mode, one window with the nxhtml-mode to correctly highlight the HTML syntax.
Could you please recommend some software that will do PHP code polishing according to pre-defined formatting rules?
Thanks!
I use Polystyle. It's quite nice and has very customizable rules. Costs $15, trial version is available. Is worth the money.
There are free ones around as well. I think there is a good formatter in some Eclipse PHP package (I forgot the name) and there is the on-line PHP Beautifier service (that one doesn't have any formatting rules, though).
I use codesniffer (http://pear.php.net/package/PHP_CodeSniffer) to check my code and keep it nice and tidy. It doesn't do any re-formatting tho, just displays a list of errors based on whichever standard you choose to check against then you go fix them by hand. Personally I prefer that tho. Its also very flexible and you can add your own standards or amend the existing ones using php