UltraEdit close matching brace - ultraedit

In most text editors, if you type in a { or " (you get the idea), the editor will automatically enter the opposite character, and put your cursor in between. I noticed that UltraEdit does not do this. Is there any way that I can setup UltraEdit so it will close a matching brace?

UltraEdit for Windows v23.20 introduced features for smart inserting of braces and quotes with Brace auto-completion and String auto-completion.
Brace auto-completion
Brace pairs defined in wordfile are auto-closed when opening brace is typed
If no braces in wordfile, or if file is not syntax highlighted, "()", "{}", and "[]" are used as defaults
Pressing Enter will reposition close brace on separate line while maintaining proper indent levels
Pressing Backspace immediately following auto-completion will remove both opening and closing brace
Typing close brace skips over auto-completed close brace without inserting second brace
Can be disabled for non-highlighted (plain text) files
Can be disabled for comments and strings
String auto-completion
Can be disabled for non-highlighted (plain text) files
Can be disabled for comments
The settings for customization of those two features can be found in configuration at Editor - Braces / strings.
UEStudio v16.20 introduced the same features with same configuration settings as UltraEdit for Windows v23.20.
Former versions of UEStudio, the IDE with UltraEdit as core editing engine, have these features from the beginning which could be customized in configuration at IDE - IntelliTips - Miscellaneous by opening from menu Advanced with a click on menu item Configuration or clicking on ribbon tab Advanced on item Settings.
But versions of UltraEdit for Windows prior v23.20 don't have those features.
However, a non smart insert of { and } with setting caret between can be easily achieved with a macro which has the key pressed to insert { assigned to the macro as hotkey.
How to create one or more new UltraEdit macros saved all together into a single macro file being configured for automatic load on startup of UltraEdit is explained in my answer on Search and replace with term list?
The UltraEdit macro code for { is:
InsertMode
"{}"
Key LEFT ARROW
The same concept can be used for:
a double quote
InsertMode
""""
Key LEFT ARROW
an opening square bracket
InsertMode
"[]"
Key LEFT ARROW
and an opening round bracket
InsertMode
"()"
Key LEFT ARROW
It is also possible to customize the macro for certain file types, for example:
IfExtIs "c"
InsertMode
"{}"
Key LEFT ARROW
ExitMacro
EndIf
IfExtIs "cpp"
InsertMode
"{}"
Key LEFT ARROW
ExitMacro
EndIf
IfExtIs "h"
InsertMode
"{}"
Key LEFT ARROW
ExitMacro
EndIf
"{"
This macro inserts } additionally to { on pressing key for { only when file extension of active file is c, cpp or h (in any case). For all other files just { is entered on pressing hotkey of macro in active mode (insert or overstrike mode).
I suggest for inserting ( with ) an even more smart code for the macro:
InsertMode
"("
IfCharIs 13
")"
Key LEFT ARROW
ExitMacro
EndIf
IfCharIs 10
")"
Key LEFT ARROW
ExitMacro
EndIf
IfEof
")"
Key LEFT ARROW
EndIf
This macro inserts first just (. If next character is a carriage return (decimal value 13) or a line-feed (decimal value 10) or the caret is at end of file, additionally ) is inserted and caret is positioned between the parentheses. In all other cases just ( is inserted into active file.
This enhancement makes it possible to modify a condition like
if(iVar == 1 || iVar == 3)
to
if((iVar == 1) || (iVar == 3))
without getting temporarily
if(()iVar == 1 || iVar == 3)
and
if((iVar == 1) || ()iVar == 3)
It is annoying to require in such cases to press key DEL to delete inserted, but unwanted ) after inserting ( somewhere in the middle of a line.

Related

Delphi DrawGrid.Canvas.TextRect changes & to _

I have a TDrawGrid where I am using its OnDrawCell event, and in there the Canvas.TextRect() method is used to fill out the cells with strings. One of the strings contains an &, but it gets displayed as an underscore _.
I don't see anything wrong, there is nothing fancy with this grid, and elsewhere it seems to work fine. Also the debugger confirms that the string is correct when passing it to Canvas.TextRect().
What am I missing?
Delphi 11, 64-bit, Windows 11.
This is expected. In Microsoft Windows, menu items, buttons, and control labels use an underscore to indicate the corresponding keyboard shortcut, and this underlined character is indicated using a prefix ampersand in code.
For instance, the &File menu item (displayed as File with F underlined) can be accessed by pressing Alt+F. A &Save button (displayed as Save with S underlined) may be invoked by pressing Alt+S (or only S if the currently focused control doesn't accept character input). You can set focus to a text field with label &Name: (displayed as Name: with N underlined) by pressing Alt+N.
This is why a string like Lost & Found is displayed as Lost _Found in Windows.
If you don't want ampersands to be treated as accelerator character indicators, simply use the tfNoPrefix flag:
Canvas.TextRect(R, S, [tfNoPrefix])
This VCL flag corresponds to the Win32 API DT_NOPREFIX flag:
Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off.

How can I remove easly Shortcodes inside a Google Sheet?

I am tryng to get rid of shortcodes inside a Google Sheet column. I have many items such as [spacer type="1" height="20"][spacer] or [FinalTilesGallery id="37"] I just would like to cancel them. Is there any simple way to do it?
Thanks !
For in-place replacement, the quick option would be to use the Find and Replace dialog (Ctrl + H) with Search Using Regular Expressions turned on, which is more powerful than your standard Find and Replace.
Find: \[.*?\] - Match anything within an open-bracket up to the very next close-bracket. This should work assuming you have no nested brackets, e.g. [[no][no]].
If you do have nested brackets, you'll have to change this to \[[^\[\]]*\]. And continue to Replace All until all the codes are gone.
Replace: Nothing.
Replace All. If you don't want to affect other sheets that may be in your document, make sure you select the right range to work with, too.
This just erases everything within the brackets.
If you want to erase any redundant spaces left by this, simply Find and Replace again (with Regular Expressions) on + (space and plus), which will match 1 or more spaces and replace with (single space).
E.g.:
string [] [] string2 -> string string2 after the shortcode replacement.
After replacing spaces, it will become string string2.
Let's say your original strings are in the range A2:A. Place the following into B2 of an otherwise completely empty Column B (or the second cell of any other empty column):
=ArrayFormula(IF(A2:A="",,TRIM(REGEXREPLACE(A2:A,"\[[^\[\]]+\]",""))))
I can't see your data, so I don't know what kind of information is between these shortcodes. If you find that this leaves you with concatenated pieces of data where there should be spaces between them, replace the above with this version:
=ArrayFormula(IF(A2:A="",,TRIM(REGEXREPLACE(SUBSTITUTE(SUBSTITUTE(A2:A,"["," ["),"]","] "),"\[[^\[\]]+\]",""))))
I can't teach regular expression language here. But I will note that, since square brackets have specific meaning within regex, your literal square brackets must be indicated with the escape character: the backslash.
Here is the regex expression alone:
\[[^\[\]]+\]
The opening \[ and the closing \], then, reference your actual opening and closing bracket sets. If we remove those, we have this left:
[^\[\]]+
Again, you see the escaped opening and closing square brackets, which I'll replace with the word these:
[^these]+
What remains there are opening and closing brackets with regex meaning, i.e., "anything in this group." And the circumflex symbol ^ as the first character within this set of square brackets means "anything except." The + symbol means "in any string length of one or more characters."
So that whole regex expression then reads: "A literal open square bracket, followed by one or more characters that are anything except square brackets, ending with a literal closing square bracket."
And we are REGEXREPLACE-ing any instance of that with "" (i.e., nothing).

Create virtualedit block around selection

I'm trying to create a script what permits me to select a few lines and create a virtualedit block around it; 1 column after the longest line.
This is my code
function! VirtualEdit()
let EndLine = line("'>")
set virtualedit = all
let maxlength = max(map(range(line("'<"), line("'>")), "virtcol([v:val, '$'])"))-1
call cursor(1,maxlength+1)
normal "^Q".EndLine."jc<space><ESC>"
set virtualedit = ''
endfunction
What it must do is
1) Control the longest line in my selection (maxlength).
2) Put the cursor on the first line in the selection at the column of the longest line +1 column.
3) Than Activate Visual Block selection (on my windows pc the command is C-Q)
4) Extend the visual block till the last line in the selection (the command on my pc for moving down = "j").
5) Than use the "c" key to insert a "space" character and ESC to exit the insert mode in order to fill the virtual block column with spaces.
However I can't find out how to use a variable (Endline) in a normal command.
I noted also that keys as and don't work in my above example.
What did I wrong?
You have many errors here:
:set does not let you have spaces around =
:set does not accept expressions, thus set ve='' is let &ve="''", not let &ve='' which is :set ve=.
:normal command also does not accept expressions, it accepts strings that are just executed. Thus :normal "^ is trying to use register ^, fails (no such register) and stops processing the rest of the line. Use :execute to pass expressions to :normal.
:normal command does not accept <Key> syntax. Neither do viml expressions, they have "\<Key>" instead (note: only double quotes and with backslash). ^Q syntax is not accepted by anybody and having raw control codes (displayed by vim as ^Q) inside a text file is not the best idea.
Don’t use :normal without a bang. Most of time you don’t need it (you need to replace ^Q with \<C-v> in this case though because it is a mapping).
Don’t hardcode virtualedit value. Instead of
set ve=all
<...>
set ve=
use
let savedve=&ve
set ve=all
try
<...>
finally
let &ve=savedve
endtry
{N}j means “N lines down”, not “go to N’th line”. “Go to N’th line” is {N}gg or {N}G.
You have let maxlen=<...>-1 and the on only line where maxlen is used you have maxlen+1. It is strange.
If you fix this you can proceed, but you don’t need adjusting virtualedit and using :normal at all:
function AddSpaces()
let [lstart, lend]=[line("'<"), line("'>")]
if lstart>lend
let [lstart, lend]=[lend, lstart]
endif
let maxcol=max(map(range(lstart, lend), "virtcol([v:val, '$'])"))
let newlines=map(range(lstart, lend), 'printf("%-'.maxcol.'s", getline(v:val))')
call setline(lstart, newlines)
endfunction

How to count lines of code (LOC) using IntelliJ IDEA?

title says everything plus:
- development language Lua
- code revision control system - Perforce (integrated with IntelliJ IDE)
Posting for posterity - This was the top Google entry when searching "intellij count lines of code" (without quotes)
.
If you're like me and didn't want to install anything else, you can hack it via the native, global search:
Ctrl + Shift + F (to open global search)
Use regex mode (check "regex" checkbox)
In the searchbox, enter only a caret "^" (without the quotes)
You may want to limit the search to a specific directory, via the "directory" tab
Hit the "Open in Find Window" button on the bottom-right
If it asks whether you want to continue, press "Continue"
.
Notes:
In regex, the caret (^) denotes the start of a line, except when inside square brackets, in which case it denotes negation
If you wanted to count non-empty lines, you could instead use "^.*\S" (without quotes), which signifies "The start of a line (^), followed by any number of characters (except newline) (.*), followed by a non-whitespace character (\S)"
You can either turn on the display of lines of code for a single file by right clicking in the left gutter and highlighting "display lines of code". Or you can do it for your entire project by downloading the Statistic plug-in. It's very nice indeed, because it shows LOC and other metrics for your entire project.

Can you grab or delete between parentheses in vi/vim?

Given this line of code in C:
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
Is there a way to delete or yank from the first bold parenthesis to its matching parenthesis? I thought about df), but that only will get you to just after the 9.0.
Is there a similar way to get vim to grab everything between matching braces, regardless of newlines?
What about dib or di(.
It will delete the inner (...) block where the cursor is.
I love text-object motions and selections!
Various Motions: %
The % command jumps to the match of the item under the cursor. Position the cursor on the opening (or closing) paren and use y% for yanking or d% for deleting everything from the cursor to the matching paren.
This works because % is a "motion command", so it can be used anywhere vim expects such a command. From :help y:
["x]y{motion} Yank {motion} text [into register x]. When no
characters are to be yanked (e.g., "y0" in column 1),
this is an error when 'cpoptions' includes the 'E'
flag.
By default, "item" includes brackets, braces, parens, C-style comments and various precompiler statements (#ifdef, etc.).
There is a plugin for "extended % matching" that you can find on the Vim homepage.
You can read the documentation on % and related motion commands by entering :help various-motions in command mode.
object-select
There is another set of motion commands that you can use in Visual mode to select various text objects.
To solve your specific problem you would do the following:
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
^
Let's say your cursor is positioned at ^. Enter the following sequence to select the part you are looking for:
v2a)
First v enters Visual mode, then you specify that you want to go 2 levels of parens up. Finally the a) selects "a block". After that you can use d or x to delete, etc.
If you don't want to include the outer parens, you can use "inner block" instead:
v2i)
See :help object-select for the complete list of related commands.
To delete all that is inside a pair of parentheses, you can always issue di( and its derivatives.
Note :
As #porglezomb suggested in his comment, you can use a ("along with") instead of i ("inside") to include the parentheses. So, using da( deletes everything inside ( and ) including ( and ).
Deleting text inside the immediate outer pair of parentheses :
So, for this line of code
printf("%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32)));
^ ^
| |
\_______\___---> Cursor range
assuming that your cursor is inside the above mentioned cursor range, you can issue the following commands :
di( --> Deletes '5.0/9.0'
ci( --> Substitutes '5.0/9.0'
yi( --> Yanks '5.0/9.0'
Deleting text inside the n-th outer pair of parentheses :
To grab everything inside the n-th outer pair of parentheses, just add n before the above command. So, with the same cursor position as above,
2di( --> Deletes '(5.0/9.0) * (fahr-32)'
2ci( --> Substitutes '(5.0/9.0) * (fahr-32)'
2yi( --> Yanks '(5.0/9.0) * (fahr-32)'
3di( --> Deletes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
3ci( --> Substitutes '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
3yi( --> Yanks '"%3.0f\t%6.1f\n", fahr, ((5.0/9.0) * (fahr-32))'
You can use d% for deleting and y% for yanking.
Place your cursor on the first parenthesis, then press v%y or v%d.
Try ci[block-surrounder]
In your case, place the cursor anywhere between the 2 parenthesis that you highlighed and try the keys: ci(
As answer of David Norman says,
Place your cursor on the first parenthesis, then press v%y or v%d.
Explanation from http://vimdoc.sourceforge.net/htmldoc/vimindex.html:
tag char note action in Normal mode
------------------------------------------------------------------------------
|v| v start characterwise Visual mode
|%| % 1 find the next (curly/square) bracket on
this line and go to its match, or go to
matching comment bracket, or go to matching
|d| ["x]d{motion} 2 delete Nmove text [into buffer x]
This means it will select everything between and including the two brackets (%) while showing the selection to you visually (v) and then yank/copy y or delete/cut d it. (To the default buffer.)
You can put/paste with p.
Made this answer to "teach myself to fish".

Resources