consider the following code :
int n,m,group=1;
char ch;
n=getint(); //WANT TO BACKWARD INDENT IT
m=getint(); //WANT TO BACK WARD INDENT IT
if(m==10)
ch='p';
else
ch='n';
...........
...........
So how would we do it in code blocks ? for forward indent , we select the block and press TAB key but what about backward especially in case when we have a large block of code?
Just Select the block :
if want to forward indent it use tab key ...
for backward use shift + tab key .....
Related
I'm trying to use the Visual Studio Macro Editor
https://visualstudiogallery.msdn.microsoft.com/d3fbf133-e51b-41a2-b86f-9560a96ff62b
which allows the user to write macros in javascript to drive the IDE. What I'd like to be able to do is write a macro that formats the text
public void Foo(
int i,
int b,
int c)
to
public void Foo
( int i
, int b
, int c
)
This should be quite trivial if I only knew the commands to do the following.
(1) Move the cursor to the next matching character, and detect if it is not found
(2) Insert a carriage return
(3) Join lines together
I have got as far as
dte.ExecuteCommand("Edit.Find");
dte.Find.FindWhat = ",";
but was hoping somebody might know their DTE commands better than I.
(1) Move the cursor to the next matching character, and detect if it is not found:
DTE.Find.FindWhat = ",";
DTE.Find.Target = EnvDTE.vsFindTarget.vsFindTargetCurrentDocument;
if (DTE.Find.Execute() == EnvDTE.vsFindResult.vsFindResultNotFound)
{
// not found
}
(2) Insert a carriage return:
DTE.ExecuteCommand("Edit.BreakLine");
(3) Join lines together:
Edit.DeleteBackwards or Edit.Delete can delete a line break when called from the beginning or from the end of a line.
(Note: This is syntax from my Visual Commander extension, but should work for Visual Studio Macro Editor as well.)
I've read the documentation for Auto Hot Key, but am new to writing scripts. I keep getting errors.
I want a very simple script - so when I use a hotkey CTRL-ALT-N - Autohotkey creates a random number that is:
3 Digits - Decimal - 8 Digits
With the very first digit of the first group being between 1 and 4.
The rest can be completely random.
Off the sample scripts I tried to edit one posted - but I am doing something wrong. If anyone could help it would be really appreciated!
The output should look like this: 314.99382028 The first number always between 1 and 4, the rest random, and decimal always the 4th character.
Then, it should just paste the number to where ever you currently are within windows - not pop up display.
Thanks for anyone who could take a quick look and help out.
Rocket
^!n:: ;<-- change this if you want a diff hotkey
Chars1 = 1234
Chars2 = 1234567890
Chars3 = .
str =
clipboard =
UpperRange = 3 ;<-- use all 3 character strings
len = 12 ;<-- number of characters in the number
; generate a new number
loop, %len%
{ random,x,1,%UpperRange% ;<-- selects the Character string
random,y,1,26 ;<-- selects the character in the string
if (x = 12) ; if numeric there are only 10 digits
}
{ random,y,1,10
StringMid,z,Chars%x%,1 ;<-- grab the selected letter
str = %str%%z% ;<-- and add it to the number string
}
clipboard = %str% ;<-- put the completed string on the clipboard
Clipwait ;<-- wait for the clipboard to accept the string`
AND THEN PASTE WHERE EVER MY CURSOR IS - Not sure how to do that.
Thanks so much for the help!
Rocket
This should do the job if I understood it correctly:
^!n::
SendInput, % "{LButton}" . RandomString(1,"1234") . RandomString(2) . "." . RandomString(8)
Return
RandomString(length,chars:="0123456789") {
charsCount := StrLen(chars)
Loop % length {
Random, num, 1, % StrLen(chars)
string .= SubStr(chars,num,1)
}
Return string
}
Since you have your answer on your clipboard, you could simply use:
Send, ^v
This will paste where your caret is, not your mouse cursor, so if you want to paste where your mouse cursor is, just add Click before....
Click
Sleep, 30
Send, ^v
Is there any way to select the text of the current line in Xcode? This would be equivalent to Cmd + l in Sublime or V in vim.
Actually you can just use the normal Mac-Shortcuts.
Beginning of Line
cmd + shift + >
Middle of Line
1. cmd + > (this brings you to the end of the line)
2. cmd + shift + < (selects everything to the left)
End of Line
cmd + shift + <
Hope this helps :)
Update
In Xcode 8, I have found the Select Line keyboard binding which you can set to cmd+l (that's L, not i) for instance to make Xcode select the line you're on right now when hitting that shortcut.
You can actually assign a key command to this. In Xcode under Preferences > Key Bindings > Text search for "Select Line" and assign it to you preferred key command (I also prefer command-l to match Sublime Text)
It's possible to select the line with ctrl + shift + a + e.
(a selects from cursor till the beginning of the line, while b selects from the cursor till the end of the line).
It's a bit long shortcut but can be useful if you end up needing only part of the line or the whole.
You can also split this into 2 steps:
ctrl + a to jump to the beginning of the line then use ctrl + shift + e to select till the end of the line.
I thought I had this before, but I must've changed a setting or something...
But say I have some code,
number = 1
number2 = 2
but now I want an if statement to wrap it
if(flag)
{
number = 1
number2 = 2
After I place the "}", is there a setting that will automatically indent those 2 lines in the block?
if(flag)
{
number = 1
number2 = 2
}
Thanks in advance!
I normally add the if statement, type { at the end of the line, hit return. This produces the block with the closing }. Then I cut-paste the code into this block - it will be indented automatically.
You can also select the code and hit cmd-] to shift it to the right.
This kind of code structure makes, IMHO, code less readable:
int func() {
[...]
}
It's just a matter of taste, but I prefer this one:
int func()
{
[...]
}
So I've trying to make a regular expression to apply in my text editor in order to make code in the first example look like the second one.
I've come up with something like ^([\t]*)([^\t{]*)({.*)$ ( I don't remember exactly if it was like this )
The idea is that when a { is found preceded of non-space characters, most probably the function header or a control structure, then split the line and send the { to the next line, but preserving the indent level (I.E. the same amount of tabs) of the original line.
The last part, about keeping the indent level is what I can't get right.
Any help appreciated.
--
PS: Feel free to disagree with my coding standards but please remember that's not the main subject here.
Here is a first try.
file.cpp:
int main() {
for (;;) {
break;
}
return 0;
}
Using sed -r s/^\(\\s*\)\(.*\)\\{$/\\1\\2\\n\\1{/ file.cpp outputs:
int main()
{
for (;;)
{
break;
}
return 0;
}
Selecting lines with sed
Grab spaces at beginning of line ^\(\\s*\).
Grab everything else except last opening brace \(.*\).
Grab opening brace until end of line \\{$.
Substitution
Put back 1st and 2nd back references \\1\\2.
Insert newline and append again 1st back reference.
Open brace.