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
Related
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
I'm building a WooCommerce site for a client using WordPress at the moment and I've written a piece of code that dynamically generates tables with products and product attributes in them. When I call the get_title() method, it gives me a title with the product's parent product first, the "→" sign, then the actual title of the product. I wrote this code to remove the "→" sign and everything before it.
$name_raw = $product->get_title();
$name = substr($name_raw, ($pos = strpos($name_raw, '→')) !== false ? $pos + 1 : 0);
It used to work perfectly, but not anymore. This code also works perfectly with every other character I've put in to test it, but not with that stupid little arrow. It seems like a recent update to something I'm using must've removed this method's ability to handle non-conventional characters. Can anyone recommend any possible solutions?
Since it's a WP environment title, the right arrow character probably has been entered using the WP form for a post. I think this character would be converted to it's HTML code, one of these:
→
→
→
→
→
→
→
So I'd do something like this:
function no_right_arrow_name($name_raw) {
if (empty($name_raw))
return $name_raw;
$right_arrows = array(
'→',
'→',
'→',
'→',
'→',
'→',
'→'
);
$name_new = $name_raw;
// removes all possible combinations of right arrows
foreach ($right_arrows as $right_arrow)
$name_new = str_replace($right_arrow, '', $name_new);
return $name_new;
}
$name_raw = $product->get_title();
$name = no_right_arrow_name($name_raw);
In netbeans, I can Ctrl+Click a variable name to jump to the declaration of that variable. This works great for normal variables. However, when I use it for a class attribute, it jumps me to the top of the class to a line like
private $myVar;
which is technically correct, but pretty much useless. It would be much more helpful if it jumped me to the line where the variable is first assigned a value, ie
$this->$myVar=7;
Is this possible? If so, how?
Using NetBeans 8.0.2 on Windows 7
as far as I know and as I have tried, this is not possible.
Because, a variable can be defined once, but can be initialized/assigned at multiple places. How will you say as which one is first?
For Example, I may be initializing the variable in the constructor method or I may be having a setter method to set the variable without the contructor too, or I may be having entirely a different method, not specifically constructor, which I may be calling to set values for variables. So there may be a chance that I have all these in my code.
Hence it's not possible.
Well, I couldn't figure it out with NetBeans macro language since I don't know how to grab the selection, modify it, and do a regex search for it, which seems like that is needed. I was able to do it with AutoHotKey. The idea is to make a macro which does the following:
Double click at the caret position to highlight the property name. Netbeans wasn't reporting its caret position, so I have to settle for using the mouse position, which is fine.
Create the following regex to locate when propName gets a value assigned:
\$this\s*\->\s*propName\s*=
Then, do a search for that regex, and go to the first instance found.
It's not perfect, but its a start and it seems to be working out for me. It currently won't work for nested properties ($this->someProp->subProp) could locate someProp but not subProp (it would incorrectly search for $this->subProp) but it should be able to handle those too by adjusting the regex.
I have assigned the macro to Alt+Click in the following:
!~LButton Up::
; //save the old clipboard
oldClipboard := Clipboard
; //Sleep a while. Without this, the double click overlaps with the
; //original click used to trigger the macro,
; //and the wrong text is highlighted (usually the thole line)
Sleep 500
Click 2 ;
; //Copy the text
Send ^c
searchText := Clipboard
; //prefix it with this regex: "\$this\s*\-\>\s*" and add "\s*=" to the end so varName becomes \$this\s*\-\>\s*varName\s*=
searchText := "\$this\s*\-\>\s*" . searchText . "\s*="
Sleep 50
; //Toggle search dialog
Send ^f
Sleep 50
; //write the text into the form
Send %searchText%
Loop, 2 {
Sleep 100
Send !g ; //turn regex on or off
; //since the state of whether regex is on or off is not known, cycle thru both
Sleep 100
Send {Enter}
}
; //restore the clipboard
Clipboard := oldClipboard
return
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.
I like to have a space after function names, arrays, that sort of thing, so a function declaration would look like:
function myfunction ($param)
{
$a = array ('a', 'b');
callfunction ($a);
}
And although I have set the style guide in Netbeans to correspond to this whenever it does autocomplete/suggestions it always misses out the space and gives me something like callfunction($a) even though when I go source->format (alt+shift+f) it then formats the code properly.
Any way to get autocomplete to add the space?
UPDATE:
Just to make things clear, I have set up Netbeans to correspond to my coding preferences, as indicated by the ability to use auto format. The problem is auto complete (or whatever the hint thing is called) does not respect these settings, leading to the missing space.
Go in Tools->Options.
In pane Editor -> choose pane Formatting.
In language choose PHP and in Category choose Spaces.
Check all in Before Keywords, Before Parenthesis, Before left braces, and you can choose other properties if you want.
Then when you will use auto-complete or Alt+Shift+F to reformat it will put the spaces correctly.
EDIT :
In the OP case it seems an other configuration prevents the auto-complete to works.
This is my config :
Do this:
Goto Options > Formatting
Scroll down to "Spaces Before Parenthesis"
Check the option called "Function Declaration"