Simple question: I am looking for the shortcut in WebStorm to select all the occurrences of a word and then replace them
e.g in my CSS file I want to select all the 'phone' variables at once and change them to 'tab-port'
Use Ctrl+ R for find and replace. This will open up a dialog at the top of the file that will look similar to the following: (depending on your IDE theme)
If you want to select all occurrences directly in the code, you can select all of them with the next shortcut:
Ctrl + Cmd + G on Mac OS X or
Ctrl + Alt + Shift + J on Windows
If you want to replace all occurrences, you can make as chazsolo said.
Related
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
I have a file with some data as follows:
795 0.16254624E+01-0.40318151E-03 0.45064186E+04
I want to add a space before the third number using search and replace as
795 0.16254624E+01 -0.40318151E-03 0.45064186E+04
The regular expression for the search is \d - \d. But what should I write in replace, so that I could get the above output. I have over 4000 of similar lines above and cannot do it manually. Also, can I do it in python, if possible.
Perhaps you could findall to get your matches and then use join with a whitespace to return a string where your values separated by a whitespace.
[+-]?\d+(?:\.\d+E[+-]\d+)?\b
import re
regex = r"[+-]?\d+(?:\.\d+E[+-]\d+)?\b"
test_str = "795 0.16254624E+01-0.40318151E-03 0.45064186E+04"
matches = re.findall(regex, test_str)
print(" ".join(matches))
Demo
You could do it very easily in MS Excel.
copy the content of your file into new excel sheet, in one column
select the complete column and from the data ribbon select Text to column
a wizard dialog will appear, select fixed width , then next.
click just on the location where you want to add the new space to tell excel to just split the text after this location into new column and click next
select each column header and in the column data format select text to keep all formatting and click finish
you can then copy all the new column or or export it to new text file
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(...))
I've recently moved from Sublime Text 3 to WebStorm 11 and I am missing a key feature when selecting occurrences of the same selection:
The ability to skip a selection (with a hotkey).
Use case
const item = { itemValue: 1, itemName: 'one' };
console.log(item.itemValue);
Selecting the first item and pressing Ctrl + G (Mac) will start selecting the item occurrences inside the object properties, and I want to select only the item right after the const and inside the console.log. Essentially, I want to skip the two item occurrences inside the object.
This is a dummy use case to illustrate the point, I know I can Refactor > Rename it.
Highlight the text you want to edit:
Ctrl+G will find the next occurrence of the highlighted text and select it:
Cmd+G will drop the current selection and select the next one:
Cmd+G one more time will drop the current selection and select the next one:
For anyone that has a different Keymap:
Cmd+G: "Find Next / Move to Next Occurrence"
Ctrl+G: "Add Selection for Next Occurrence"
Right now, the only solution I found is using Find:
Select the text and press Cmd + F (the find bar will open with the selected text as a search)
Press Cmd + G to select the next occurrence
Press Enter to skip it (will select the next occurrence)
Press Enter again
Press Esc to exit the find context
And now the desired items are selected and ready for editing.
At least it's doable, but I'd expect a hotkey to just skip the current occurrence.
How can I use regular expression in excel ?
In above image I have column A and B. I have some values in column A. Here I need to move data after = in column B. For e.g. here in 1st row I have SELECT=Hello World. Here I want to remove = sign and move Hello world in column B. How can I do such thing?
Stackoverflow has many posts about adding regular expressions to Excel using VBA. For your particular example, you would need VBA to actually move a substring from one cell to another.
If you simply want to copy the substring, you can do so easily using the MID function:
=IFERROR(MID(A1,FIND("=",A1)+1,999),A1)
I used 999 to ensure that enough characters were grabbed.
IFERROR returns the cell as-is if an equals sign is not found.
To return the portion of string before the equals sign, do this:
=LEFT(A1,FIND("=",A1&"=")-1)
In this case, I appended the equals sign to A1, so FIND won't return an error if not found.
You can use the Text to Column functionality of MS-Excel giving '=' as delimiter.
Refer to this link:
Chop text in column to 60 charactersblocks
You can simply use Text to Column feature of excel for this:
Follow the below steps :
1) Select Column A.
2) Goto Data Tab in Menu Bar.
3) Click Text to Column icon.
4) Choose Delimited option and do Next and then check the Other options in delimiter and enter '=' in the entry box.
5) Just click finish.
Here are URL for Text to Column : http://www.excel-easy.com/examples/text-to-columns.html