Vim Snipmate or Plugin to Autocomplete PHP Object Syntax - php

Is there a plugin or snippet that I can use to automcomplete -> or => by pressing - or = + tab?
I just can't stand typing > all the time.
I tried creating the following snippets for snipmate, but they don't work because - and = are affixed to the end of a variable.

Here's a snippet for you:
:inoremap <expr> <Tab> getline('.')[col('.')-2]=~#'[-=]' ? ">" : "\<Tab>"
This is an expression mapping that maps <Tab> in insert mode to > if the character before the cursor is either - or =.
See :h :map-expression.

Related

Search / Replace All PHP Variable in Blade using Visual Studio Code

So, I am just curious if there are any simple method to select / replace all declared PHP variable in blade using Visual Studio Code. Because, I am trying to make the static version from its original version and the code itself has ~~500 line of code so it would take some times to remove / edit those variables manually. Or maybe using Regex Method ? (since I am not really expert about those regex rules).
Thanks before
Ctrl + Shift + F
this is the VS Code shortcut

Formatting in netbeans?

I want to know how can I configure my netbeans ide to format my code in my specific need.
I need all my assignment in same line to easily distinguish it.
for eg:
$a = 1;
$b = 1;
$c = 1;
$a++;
some code
$d = 1;
Based on your sample code, I'm assuming that you want to do this for PHP. If so, then you can do it as follows:
Select Tools > Options > Editor, then click the Formatting tab.
Select PHP from the Language drop list, then Alignment from the Category drop list.
A code sample will be displayed in the Preview window on the right side of the screen which includes some variable assignments near the end of the code:
Under Group Multiline Alignment check the Assignment box. Note that the assignment operators (=) in the code preview are now aligned:
Notes:
The column position used for aligning the assignment operators is dynamic, based on the length of the longest variable name. I don't think it is possible to place the assignment operator in a specific column as suggested by your code example.
This approach is specific to PHP, and can't be used for formatting code in other languages such as Java or JavaScript.
Formatting in NetBeans can be configured under "Tools / Options / Editor / Formatting", but I don't think that you can configure NetBeans to use your desired format.

How to select the whole variable name including $ in Visual Studio Code in PHP?

I am using the latest version of Visual Studio Code and I am using the PHP programming language. I am selecting a variable but it only selects the variable name, not the $ symbol.
By default it selects like this:
But I want it like this:
Is there any setting that enables this behavior?
Any information on this would be greatly appreciated. Thanks!
The best way is to edit the VsCode settings.json and specify it for the PHP language.
You can open it typing VsCode command:
Preferences: open settings (JSON)
And specify inside the "editor.wordSeparators" setting for your language removing the '$' symbol:
"[php]": {
"editor.wordSeparators": "`~!##%^&*()-=+[{]}\\|;:'\",.<>/?"
}
You need to remove the $ symbol from the editor.wordSeparators directive. This is the default value:
// Characters that will be used as word separators when doing word related navigations or operations.
"editor.wordSeparators": "`~!##$%^&*()-=+[{]}\\|;:'\",.<>/?",
You can make this language specific if you want, so it only applies to PHP.
you can do it in a simple way
file > preferences > Settings
Extensions -> PHP
in file settings.json
{
"editor.wordSeparators": "`~!##%^&*()-=+[{]}\\|;:'\",.<>/?"
}

Automatically convert short array syntax to long (traditional) in PhpStorm?

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.

Sublime Text autocomplete function with variable in parentheses?

If I already have this written
$company_id = isset($_POST['cid']) ? $_POST['cid'] : null;
And I want to wrap a function call around $_POST['cid'], is there a way to put that inside the autocompleted function's parentheses?
Instead of me typing this:
$company_id = isset($_POST['cid']) ? Validate::isId()$_POST['cid'] : null;
and then having to erase the right parenthesis, is there a shortcut to wrap the param when sublime autocompletes the function for me?
$company_id = isset($_POST['cid']) ? Validate::isId($_POST['cid']) : null;
Using Mac Yosemite and SublimeText 3.
You can create a custom snippet that accepts a SELECTION argument:
Save The Code Below #:
Packages/___Your_Snippet_Folder___/SnippetName.sublime-snippet
 
<snippet>
<tabTrigger>testFunction()</tabTrigger>
<description>testFunction</description>
<scope>source.php</scope>
<content>
testFunction(${1:$SELECTION}, ${2:PlaceHolder_2})
</content>
</snippet>
The use of placeholders, for example: ${1:placeholder_text_goes_here} , allows you to assign descriptive pre-selected regions throughout your snippet that can be navigated with Tab & Shift + Tab
Additionally, you can replace one of the placeholders with $SELECTION, for example: ${1:$SELECTION} , which will pass the currently selected text as an argument if you execute the snippet from the command palette or a key-binding.
To insert the snippet:
select the text to be passed as the $SELECTION argument
use Ctrl + Shift + P to launch the command palette
type Snippet: followed by the value of the <description> key in your sublime-snippet file
For more information on snippets, see:
SublimeText / Unofficial Docs / Snippets

Categories