How to Select all codes between Curly Braces in Notepad++? - if-statement

In Notepad++ How to select all (Highlight) codes between Curly braces (Start & End)? For eg. If-else, Method definition, While, For loop etc. I remember similar option is available with Adobe Dreamweaver where we can perform this CTRL ' (Holding the control key & single quote together). In Notepad++ How to achieve the same?
Thanks In Advance.

From Notepad++ v6.4.4: This feature got added in - Add selection between matching braces feature.
How to achieve :
Select a curly brace { press Ctrl+Alt+B to highlight the section.

At Settings->Preferences->Delimiter, change the delimiters from parentheses to braces and check the multi-line box. Then you can Ctrl-double-click on either brace to highlight everything in between.
Also, to jump between braces you can use Ctrl-b.

You can take the help of this attached image

Put your cursor at the starting of the curly brace, it will go red and together its complementy will also go red, locate this red closing curly brace, hold your shift key and click on this closing red brace. you code will be selected ...

Related

regular expression to relace fixed characters with space

I need help in doing a simple replace in notepad++.
There is a fixed length of characters which needs to be replaced.
Attached screenshot.
example:
{111:001}{121:7c9cae72-49cb-4ef7-a576-d87af47ae74a}
{111:001}{121:2f0b8607-07d3-429b-a00c-7ed4b7f73358}
Common is: {111:001}{121:
And rest till the closing curly braces "}" is dynamic text.
Can someone please assist in creating a replace function to find all the lines
where the text starts with "{111:001}{121:" and the rest of the characters can be something else until it finds the closing curly brace "}".
if the entire text is found then should replace with blanks.
#Yashas solution worked absolutely fine:
\s*{111:001}{121:.*}

Regular expression to select text across multiple lines

I am trying to write a regular expression to select text between two curly braces in a Java file. Text between braces may be spread across multiple lines.
Eg.,
{
// line1 ;
// line 2 ;
// line 3 ;
}
I need to select all the lines in between braces.
I tried \{[.]*\} but it doesn't select multiple lines.
Please suggest me in this regard.
Thanks.
Generally, this is not a good idea as you need to take nested brackets, etc. into account. You might be better off using a parser instead.
This being said, you might get along with the following construct:
^\{
(.+?)
^\}
This assumes, that your opening and closing brackets stand alone in one line. If you want to allow whitespaces as well, you'll need to alter it to:
^\s*\{
(.+?)
^\s*\}
See a demo on regex101.com (and mind the different modifiers, ie DOTALL and MULTILINE !).
You need to add line breaks in the regular expression... Try this:
\{(.*\r\n)*\}

Replace line breaks

I am using visual studio code for several things. Everything is working fine, but I cannot get one specific thing to work.
I need the ability to remove line breaks from the text.
Example:
first line
second line
Should become:
first linesecondline
Since a recent update it is possible to search for line breaks with using ^$.
It is described here: https://github.com/Microsoft/vscode/pull/314
The problem I have is that when I use this for replacing, it does actually "add" to the line break and does not "replace" it.
The latest version of VS Code has a shortcut to join lines (some may say remove breaks) from selection: CTRL + J.
I found that (at least on Windows) the solution was to use search and replace with a regular expression. Search for $\n and replace with nothing to get rid of the newlines. Note that the newline character that we want to replace is placed after the end of line matcher ($).
#tripleonard hint did not work for me (no shortcut key assigned), so what I did was first ctrl+shift+p to list all commands and then just type Join lines
I'm able to manage this with the search and replace tool and "Use Regular Expression" enabled. Search for the pattern \n$ and replace with $
In my case shorcut in VS Code was not set. It took me a while to find out what command in VS Code am I looking for. For other with same problem it is: "Join lines".
Turn on regex mode and find and replace.
Search for \n and replace with nothing.
Select the new line, and press ctrl+D (and hold it).
Then press ctrl+h, you will be able to replace it with whatever you need.
On Mac, use cmd+a to select all lines. Then, use cmd+shift+p to open commands and type Join Line and click on it.
You can use \n to search for new lines
but while finding/searching,
the Use Regular Expression option should be enabled
Press ctrl+f or ctrl + h
Copy and past this ^(\s)*$\n expression into top input field
after click on the * icon, then you can see all white lines break.
Past bottom input field = \n //one line break
That means what you want to replate in white line break
After click on the Replace or Replace All Icon button
https://bitcoden.com/answers/visual-studio-code-delete-all-blank-lines-regex

How to customize indentation in Geany

Based on geany documentation
Geany knows four types of auto-indentation:
None: Disables auto-indentation completely.
Basic: Adds the same amount of whitespace on a new line as on the last line.
Current chars:
Does the same as Basic but also indents a new line after an opening brace '{', and de-indents when typing a closing brace '}'. For Python, a new line will be indented after typing ':' at the end of the previous line.
Match braces:
Similar to Current chars but the closing brace will be aligned to match the indentation of the line with the opening brace.
I am developing new editor for new DSL. I don't have any kind of braces, so indentation must be based on strings. How can I apply auto-indentation to my custom syntax. Is there any short and easy way?
Scintilla can be the thing that you are looking for. Strategy which used while implementing folding inside LexDSL.cxx can be a solution for it. Level based implementation of code folding can also determine the deepness of the tab. Each level means new tab and using that strategy could make customization of indentation in geany be possible.

Vim regular expression to remove block of code for all the lines

In my code I want to remove a block of code that starts with a bracket and ends with a bracket. For example if I have this line
ENDPROGRAM { fprintf(sdfsdfsdfsd....) }
and after running the regex i want it to just end up with
ENDPROGRAM
I want to only delete code inside the bracket and the brackets themselves. I tried this command
:%s/\{[a-zA-Z0-0]*\}//g
but it says that pattern not found. Any suggestion?
ENDPROGRAM is just an example, I have like DIV MULT etc etc
Since you're using Vim, an alternative is to record a keyboard macro for this into a register, say register z.
Start recording with qz.
Search forward for ENDPROGRAM: /ENDPROGRAM[enter]
Scan forward for opening brace: f{
Delete to matching brace: d%
Finish recording q.
Now run the macro with #z, and then repeat with ##. Hold down your # key to repeat rapidly.
For one-off jobs not involving tens of thousands of changes in numerous files, this kind of interactive approach works well. You visually confirm that the right thing is done in every place. The thing is that even if you fully automate it with regexes, you will still have to look at every change to confirm that the right thing was done before committing the code.
The first mistake in your regex is that the material between braces must only be letters and digits. (I'm assuming the 0-0 is a typo for 0-9). Note that you have other things between the braces such as spaces and parentheses. You want {.*}: an open brace, followed by zero or more characters, followed by a closing brace. If it so happens that you have variants, like ENDPROGRAM { abc } { def }, this regex will eat them too. The regex matches from the first open brace to the last closing one. Note also that the regex {[^}]*} will not work if the block contains nested interior braces; it stops at the first closing brace, not the last one, and so ENDPROGRAM { { x } } will turn to ENDPROGRAM }.
The second mistake is that you are running this on all lines using the % address. You only want to run this on lines that contain ENDPROGRAM, in other words:
:g/ENDPROGRAM/s/ {.*}//
"For all lines that contain a match for ENDPROGRAM, find a space followed by some bracketed text, and replace it with nothing." Or else:
:%s/ENDPROGRAM {.*}/ENDPROGRAM/
THIS looks like a job for: (dum da dum duuuuum!)
TEXT OBJECTS!
Place the cursor anywhere within the braces. Type daB.
WOOOOOOOAAAH what just happened?!
aB is something called a "text object" in Vim. You could also have typed da{ or da} in this situation. A text object is a thing that Vim's operators can act on. d is one such operator. I'm sure you know others: c, y, etc.
Visual mode also works on text objects. Instead of daB, try vaB. This will select all the text in the braces, plus the braces themselves. Most text objects also have an "inner" variant, for example ciB would delete everything inside the braces, and enter insert mode, leaving the braces intact.
There are text objects to work with HTML/XML tags, objects for working with quoted strings, objects for sentences and paragraphs, objects for words and WORDS, and more. See the full list at :help text-objects.
When something is broken, start simple and work up to what you need. Do not worry about the :s command at first; instead, focus on getting the pattern (or regular expression) right.
Search for \{ and you will get an error message. Oops, that should be just {.
Add the character class: {[a-zA-Z0-0]*. Darn, that is not right, because you left out the space.
Next try: {[a-zA-Z0-0 ]*. Now we are getting somewhere, but we also want to match the parentheses and the dots: {[a-zA-Z0-0 ().]*.
Add the closing brace, realize that you really meant 0-9 instead of 0-0, and you are done: {[a-zA-Z0-9 ().]*}.
At this point, you can take advantage of the fact that :s uses the current search pattern by default, so all you need is :%s///.