Recently I've begin moving to sublime text 3 from Netbeans.
I've discovered almost all needed features but still can't find one.
There is a cool feature in Netbeans:
It does the following. If I have such code:
$product = new Product;
$product->someMethod();
I don't need actually to type - and then shift + > to get -> . It's enough just to presss - sign and Netbeans figures out on his own that it should be -> .
The same is applied to array.
I understand that Sublime doesn't do as deep code analysis as Netbeans does.
Of course it would perfect solution if it could figure out like Netbeans does.
But I would happy to replace - sign on numpad keyboard to -> always.
I've tried snippets. It looks like this:
It works ok. But only if it goes as the first symbol in the word.
But then I need to reference an object referencing never goes first.
I can't believe that all people type manually every time - and shift+> to get referencing the object. There must be better way.
Any ideas? How did you tackle this problem?
Looks like there is no silver bullet which would kill any beast.
Though ST is a cool editor it's just editor, it's good for js, scss,css, python where Netbeans sucks but too bad for php.
Probably I would be happy with ST for PHP if I didn't know that you can get more boosting using full-blown IDE.
So frontend development will be carried on ST and backend on Netbeans.
Edit
Of course I tried the whole bunch of available plugins. This is the list of tried:
To replace the - key with -> in all situations in Sublime Text (meaning if you want to write, for example 1 - 2, you would have to type 1 -backspace 2, you can do the following:
From the Preferences menu in Sublime Text
Click Keybindings - User
Write [{ "keys": ["-"], "command": "insert", "args": { "characters": "->" } }] (note that this assumes that you don't already have anything in the user keybinding file. If you do, before the ] at the end of the file, type , and the above without the enclosing [ and ] characters. The file needs to be a valid JSON array of keybindings.)
Save it
Try typing - and see the magic
You may be able to do some magic with contexts to get this keybinding only for PHP syntax files, or you could just write a simple Python plugin that your keybinding would execute, which would enter - in the document if it is not a PHP file and -> if it is.
Related
How to automatically convert short array syntax to long(traditional) in PhpStorm?
I used the feature "Code -> Inspect Code" in PhpStorm and then one by one click convert short syntax to long.
Inspect code
Manually convert
There has to be a way to automate this job? Are there macros in PHPStorm?
go to Settings(Ctrl + Alt + S)-> Editor -> Code Style -> PHP -> Code Conversion -> Array Declaration Style -> tick Force short declaration style Checkbox.
press OK -> press Ctrl + Alt + L -> voila
Bartosz is right. To avoid manual work you can use Short Array Syntax Converter tool with revert (short into long array syntax) option. But be aware, that
Reverting has not yet been thoroughly tested, so use with extreme
percaution!
I'm afraid it's not possible. If it was a failing inspection, there would be a "Fix all problems in file" option in the submenu. Intentions don't have this functionality.
Have You tried setting PHP version to 5.3 and then only search for this via Inspect code? Don't have PhpStorm installed anymore.
I need to be able to generate debugging statements for my code. For example, here is some code I have:
$this->R->radius_ft = $this->TC->diameter / 24;
$this->R->TBETA2_rad = $this->D->beta2 / $rad; //Outer angle
$this->R->TBETA1_rad = $this->R->inner_beta1 / $rad; //Inner angle
I need to be able display results of computations so that they can be read by a human.
So far I have been doing this (example showing first line from above only):
$this->R->radius_ft = $this->TC->diameter / 24;
if (self::DEBUG)
print("radius_ft({$this->R->radius_ft}) = diameter({$this->TC->diameter}) / 24");
The above print something like radius_ft(1.4583) = diameter(35) / 24 and a few of those lines looks like equations and are nicely traceable when I want to verify things on paper, or if I want to expose the intermediate work of the computations to someone else.
The problem is that it is a pain to construct those debugging statements. I craft them by hand, and usually it is not a problem, but in my current example, there are hundreds of lines of code where this needs to be done. Much pain.
I was wondering if there are facilities in PHP that will allow me to make print-outs of statements showing what each line of code does. Or methods to semi-automate creating the debug lines for me.
I have so far discovered this method to cut down on some of the work .... use Macro facilities of a text editor.
Paste line of code into TextPad (or similar editor that supports macros). Record macro and use Search, Mark and Copy facilities to carefully navigate between special symbols of the variable, such as $, >, and symbols that are not alphanumeric or $, >, etc. while copying and extracting and pasting parts of variable to craft my particular statement.
Exact steps may differ for one's needs. My macro operates on one variable like $this->R->radius_ft with cursor at the start and ends up with something like radius_ft({$this->R->radius_ft}), with cursor a few chars after the end, sometimes coinciding with the next variable to process.
Perhaps same could be done with regular expressions but I like the way Macro does it - I can process a variable and go to the next one and just repeat the macro with a hot key combination. This takes out the most tedious chunk of work for me.
Alternatively - hand the person the code and let them figure it out. Teach them how to read code.
I know there are a lot of questions on this topic, I've been reading and trying different ideas for hours.
I'm fetching data using the Dropbox api, which works fine, but it's slow.
So I'm moving this fetch to ajax.
The json response has the ever popular invisible question mark appended to the end of the string... after the closing square bracket.
.....}]?
This makes the json object invalid and none of the regular functions work on invalid json.
It's there when I load the page direct, but goes away when I set autoRender to false. So I got it working.... but, I would like to find this little POS and remove it before it shows up randomly in the future. It took hours to figure out that this was problem because it's invisible!
I can use Notepad++ to eradicate the little beasty, but I can't find it!
I've tried the following...
grep -rlI $'\xEF\xBB\xBF' .
Total Commander -> go to project's root dir -> find files (alt+f7) -> file types . -> Find text "EF BB BF" -> check 'Hex' checkbox -> search
search in project for charset=iso-8859
Tried this hack
$response = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $response);
I use Netbeans which near as I can tell is worthless for this problem.
Keep in mind, this is Cakephp 2.3, so there are about 3.7 million files that get loaded.
How do you find these things??
Is there any way to show the current PHP function or class name in the VIM command line? I found a plugin for showing C function names in the status line but it does not work for PHP and in any case I prefer the command line be used to save valuable vertical lines.
Thanks.
EDIT
While looking for something completely unrelated in TagList's help I've just found these two functions:
Tlist_Get_Tagname_By_Line()
Tlist_Get_Tag_Prototype_By_Line()
Adding this in my statusbar works beautifully:
%{Tlist_Get_Tagname_By_Line()}
Also, did you read the Vim Wiki? It has a bunch of tips trying to adress the same need. There is also this (untested) plugin.
ENDEDIT
If you are short on vertical space maybe you won't mind using a bit of horizontal space?
TagList and TagBar both show a vertical list of the tags used in the current buffer (and other opened documents in TagList's case) that you can use to navigate your code.
However, I'm not particularly a fan of having all sorts of informations (list of files, VCS status, list of tags, list of buffers/tabs…) displayed at all times: being able to read the name of the function you are in is only useful when you actually need to know it, otherwise it's clutter. Vim's own [{ followed by <C-o> are enough for me.
I don't know anything about PHP, and I'm not trying to step on anyone's toes, but having looked at some PHP code I came up with this function which I think takes a simpler approach than the plugins that have been mentioned.
My assumpmtion is that PHP functions are declared using the syntax function MyFunction(){} and classes declared using class MyClass{} (possibly preceded by public). The following function searches backwards from the cursor position to find the most recently declared class or function (and sets startline). Then we search forward for the first {, and find the matching }, setting endline. If the starting cursor line is inbetween startline and endline, we return the startline text. Otherwise we return an empty string.
function! PHP_Cursor_Position()
let pos = getpos(".")
let curline = pos[1]
let win = winsaveview()
let decl = ""
let startline = search('^\s*\(public\)\=\s*\(function\|class\)\s*\w\+','cbW')
call search('{','cW')
sil exe "normal %"
let endline = line(".")
if curline >= startline && curline <= endline
let decl = getline(startline)
endif
call cursor(pos)
call winrestview(win)
return decl
endfunction
set statusline=%{PHP_Cursor_Position()}
Because it returns nothing when it is outside a function/class, it does not display erroneous code on the statusline, as the suggested plugin does.
Of course, I may well be oversimplifying the problem, in which case ignore me, but this seems like a sensible approach.
I have been using gvim for a while and now im trying eclipse and a feature that I really miss is the auto complete. Not just typing pre and getting preg_replace as a suggestion, but if I have a variable name that I have been using like $_POST['confirm_delete'] then confirm_delete comes up as a suggestion if I type con.
Can I get this feature with eclipse?
Yes, Eclipse does have autocomplete. But not for unknown array indices like $_POST['myindex']. Autocomplete works for all your normal variables and classes/methods.
This might help : once you have already typed confirm_delete in your file somewhere, you can use eclipse's global autocomplete feature Alt + /. For example if you type con and Alt + / it will complete it with confirm_delete if it is the only word in the file that starts with "con" (otherwise type a few extra letters to be sure).
This works everywhere in the file, even in comments.
Eclipse (also Netbeans) cant auto complete array indexes.