Notepad++, shortcut to add brackets around highlighted text - replace

I recorded a macro to type curly braces {} using a given shortcut
Can I record a macro that takes any given highlighted text (word(s)), and adds the curly braces around it?
So I can highlight the words:
test here
and click the shortcut created with a macro, and turn the text to:
{test here}

This will work with one or many words:
1) Mark text
2) Goto Macro -> start recording
3) Cut highlighted text (CTRL+X)
4) Type: "{" then do CTRL-V then Type "}"
5) goto Macro -> Stop Macro
6) Save Macro as a shortcut
this should do the trick

Might be this should help:
TextFX > TextFX Edit > Indent and surround { text line }

Related

Exptra parens generated after nested IFs libreoffice

I enter:
=IF(D4=”4x4”, _4x4PT*e4, IF(D4=”4x6”,_4x6PT*e4, 0))
when I press I get:
Err:501
When I click on the cell I see:
=IF(D4=”4x4”, _4x4PT*e4, IF(D4=”4x6”,_4x6PT*e4, 0)))
Libreoffice has added an extra paren(s) at the end?
(_4X4PT and _4x6PT are cell names)
Substituting 7 and 11 for the two cell names makes no difference
How do I fix this?
Don't use smart quotes ”. Calc expects normal quotes " instead. Now Calc will no longer add an extra parenthesis.
Depending on regional settings, you may now get Err:508 and need to change the commas , to semicolons ; instead. Semicolons are universally accepted by Calc as a delimiter.
Entering the following expression does not produce an error:
=IF(D4="4x4"; _4x4PT*e4; IF(D4="4x6";_4x6PT*e4; 0))

Remove numbers and parentheses at the beginning of each line in Notepad++

Basically every line in my text file is formatted like this:
1) Baker
2) Photographer
3) Doctor
4) Teacher
5) CEO
etc, etc.
Using Notepad++ how do I remove the 1), 2), 3), etc?
1 ) Press Ctrl + H for pop window to Replace.
2 ) Provide the ^\d+\) regular expression in Find what text field, choose option Regular expression in search mode and make empty in Replace with text field.
3 ) Click on Replace all or Replace button.
You can use the regex ^\d+\) (note the trailing whitespace) and replace text matching this pattern with an empty string.
Step-by-step guide:
Press Ctrl+h to open the Replace dialog.
Press Alt+F to focus on the Find text field.
Enter ^\d+\) and press Alt+l to switch to the Replace with text field.
Press backspace to delete any text that might be in this box.
Press Alt+g to switch the search mode to regular expression.
Press Alt+a to perform a replace all operation on the document.
You can use the column selection mode, normally accessed with alt + mouse, or by the edit menu, select the 2 columns, and delete them as any text

notepad++ Stop replacing at a specific line

I've been trying to figure something out for a while now and I can't seem to understand. I've looked everywhere and I still can't find it.
I'm trying to make a dictionary for an auto corrector with AutoHotKey and I need to replace the beginning of each line with "::" and somewhere in between the line with another "::"
like so:
::togehter::together
Now I have around 20,000 of these to add with no "::" yet and what I'm doing is this in the replace textbox:
Replace: ^
With: ::
Now it works fine for the first line BUT if I press replace all cause no way am I going to click 20,000 times on replace, it replaces not only from where I am to the bottom but also the beginning too. So every line now has a new "::" added.
So what I need is to be able to tell the replace at what line to stop instead of doing every single line.
Also if you could help me add the "::(word)" after the first ::(misspelled word) that would be a great help.
Image for reference
I have found that the regular expression replace-all of ^ with some text, i.e. to add some text at the start of every line, does not work in some versions of Notepad++. My workaround for this was to use the ^(.) as the search string and include \1 in the replacement. For your case the replacement would be ::\1. The effect here is to replace the first character of each line with :: plus the first character. In a quick test with Notepad++ v7.1, replacing ^ with :: worked as I would want.
Two things should be checked in the Replace dialogue before doing the replace-all: (1) that "Regular expression" is selected and (2) "In selection" is not selected.
The question is not clear how the two words in the input are separated, so assuming that one or more spaces or tabs is used the search string to use is ^(\w+)\h+ and the replace string is ::\1::.
This AutoHotkey script might do what you require.
It leaves unchanged lines that start with '::',
and prepends/replaces text in the others. You copy the original text to the clipboard, run this script, and then the desired text is put on the clipboard. (To create and run the script: copy and paste it into a text editor and save it as myscriptname.ahk, or myscriptname.txt and then drag and drop the file into the AutoHotkey exe file. Or alternatively, if you save it as an ahk file, and install AutoHotkey, you can double-click to run.) AutoHotkey
vText := Clipboard
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2*2)
StringReplace, vText, vText, `r`n, `n, All
Loop, Parse, vText, `n
{
vTemp := A_LoopField
if (vTemp = "")
if (1, vOutput .= "`r`n")
continue
if (SubStr(vTemp, 1, 2) = "::")
if (1, vOutput .= vTemp "`r`n")
continue
StringReplace, vTemp, vTemp, %A_Space%, ::, All
vOutput .= "::" vTemp "`r`n"
}
Clipboard := vOutput
MsgBox done
Return

replacing brackets

I would like to replace all occurrences of "exp( ... )" with "Exp[ ... ]" in the following (essentially changing from Matlab to Mathematica syntax):
exp(-(pi*k2*2i)/3)*(v9/4 + (3^(1/2)*(v8/2 + (3^(1/2)*v9)/2))/2 + (3^(1/2)*v8)/12) + exp((pi*k2*2i)/3)*(v9/4 + (3^(1/2)*(v8/2 + (3^(1/2)*v9)/2))/2 + (3^(1/2)*v8)/12) ...
Is it possible to automate this with vim, sed, or awk? The trick is not replacing all "(" with "[", only the ones that occur immediately after exp and the corresponding pair.
You can do that with a vim macro.
Let's clear the a register by pressing qaq. ( In case if any previous operations are recorded, we can clear them)
Start a macro recording by pressing qa.
Search for exp( by typing/exp(/e. this will put the cursor at (.
Press % to move to its closing bracket. Press r] to replace it with ].
Now, press N to move to exp(. Press r[ to replace it with [. Press #a to recursively replace all such instances. Press q to stop recording.
Now, you can press#a to play the macro and it will replace everywhere.
In the following sed script (brackreplace) we are:
exp( → Exp§
hide balanced (...) → «...» (if they have no "()§" inside)
Exp§...) → Exp[...]
restoring hidden parentesis
#!/bin/sed -zf
s/exp(/Exp§/g # (1) protect exp( → Exp§
s/(\([^()§]*\))/«\1»/g # (2) hide balanced (...) → «...»
s/Exp§\([^()§]*\))/Exp[\1]/g # (3) Exp§...) → Exp[...]
s/«/(/g # restore protected parentesis
s/»/)/g
This cover your example; repeat line (2) if you expect deeper () inside exp(...).
After chmod, this command may be used in command line or inside the editor. Example with vim:
:%!bracketreplace
Just like Sibi's answer, but just a subtle change, you should use `` to jump back to the matching brace instead of N. otherwise it doesn't work with this pattern: exp(...exp(...))

Vim: Align continous lines with spaces

I would like to indent everything in vim with tabs, except a particular case. For example I have this c++ code(where <tab> is a tab character series and <s> is a space character series):
<tab>if(true &&
<tab><s>true)
<tab>{
<tab><tab>//code here
<tab>}
I would like after writing '&&' and press 'o' to jump on the next line and start writing to make vim put a tab and the number of spaces till '(' from the line before.
Is it possible to define this coding style in vim?
Thanks!
I think what you're looking for is the (N option for cinoptions. Try set cinoptions+=(0. According to the documentation, this looks like the alignment that you seek.
More information can be found by using help command: :help cinoptions-values or looking at the online version of the help for cinoptions-values.
As far as tabs go, you'll want to disable expandtab with :set noexpandtab, and you'll want to make sure your tabstops, soft tabstops, and shiftwidth are all set accordingly. As an example, the Linux source code uses a style like you mention above, and I have this in my vimrc:
setlocal ts=8 sts=8 sw=8 tw=80
" Don't expand tabs to spaces.
setlocal noexpandtab
" Enable automatic C program indenting.
setlocal cindent
" Don't outdent function return types.
setlocal cinoptions+=t0
" No extra indentation for case labels.
setlocal cinoptions+=:0
" No extra indentation for "public", "protected", "private" labels.
setlocal cinoptions+=g0
" Line up function args.
setlocal cinoptions+=(0
" Setup formatoptions:
" c - auto-wrap comments to textwidth.
" r - automatically insert comment leader when pressing <Enter>.
" o - automatically insert comment leader after 'o' or 'O'.
" q - allow formatting of comments with 'gq'.
" l - long lines are not broken in insert mode.
" n - recognize numbered lists.
" t - autowrap using textwidth,
setlocal formatoptions=croqlnt
Add following in your .vimrc
set tabstop=2
set expandtab
set shiftwidth=2
set smarttab
set linebreak
set smartindent
set cindent
set autoindent
This is all you need to roll out awesomeness in vim. :)