Adding comma and quotes for two columns in sublime on Mac - sublimetext3

I have data in sublime arranged as follows;
353154 0.001039699782
506472 0.02085443362
482346 0.08343533852
439791 0.001349253676
486087 0.9999999476
I am trying to put quotes and commas so as to get following output;
('353154', '0.001039699782'),
('506472', '0.02085443362'),
('482346', '0.08343533852'),
('439791', '0.001349253676'),
('486087', '0.9999999476')
I am aware of using CMD+Shift+L in order to move cursors right and left. But I need help on how to get the commas and quotes between the two columns. Kindly advise.

You can do this with regex search and replace. Select Find → Replace… and make sure the Regular Expression button (usually looking like this *) is selected. In the Find: field, enter
([\d\.]+)\s+([\d\.]+)
and in the Replace: field, enter
('\1', '\2'),
Hit Replace All and it will look like this
See the demo at regex101.com, which also explains what each of the capture and replacement groups do.
Please keep in mind that you'll have to delete the final comma , if that's not proper syntax for your language of choice.

Related

Is there any way to copy few characters to clipboard in textpad?

I'm trying to replace a few character word in one place with the word searched in another. I.e
VARIABLE INT005 SOME TEXT BETWEEN NAME=INT020;
I want the program To copy whats after VARIABLE (INT005 in this case) and paste it after NAME=(here should be again INT005 replaced into the place of INT020)
A regex replacement should work here. Assuming you are only looking to make these replacements on a single line, you may try the following find and replace:
Find: \bVARIABLE (\S+)(.*?)\bNAME=\S+;
Replace: VARIABLE $1$2NAME=$1
Demo
Edit:
If your text could span multiple lines, then either turn on "dot all" mode from Textpad (not sure where you would do that), or use this find version:
\bVARIABLE (\S+)([\s\S]*?)\bNAME=\S+;

Add parenthesis to vim string

I'm having a bit of trouble using parenthesis in a vim string. I just need to add a set of parenthesis around 3 digits, but I can't seem to find where I'm suppose to correctly place them. So for example; I would have to place them around a phone number such as: 2015551212.
Right now I have a strings that separates the numbers and puts a hyphen between them. For example; 201 555-1212. So I just need the parenthesis. The final result should look like: (201) 555-1212
The string I have so far is this: s/\(\d\{3}\)\(\d\{3}\)/\1 \2-/g
How might I go about doing this?
Thanks
Just add the parens around the \1 in your replacement.
s/\(\d\{3\}\)\(\d\{3\}\)/(\1) \2-/g
If you want to go in reverse, and change "(800) 555-1212" to "8005551212", you can use something like this:
s/(\(\d\d\d\))\ \(\d\d\d\)-\(\d\d\d\d\)/\1\2\3/g
Instead of the \d\d\d, you could use \d\{3\}, but that is more trouble to type.

Notepad++ Search Multiple and Replace Respectively

Doing some String manipulation and I want to ask if the below is possible in Notepad++:
I have a string with Years:
10-Jan-13
22-Feb-14
10-Jan-13
10-Mar-13
I want
10-JAN-13
22-FEB-14
10-JAN-13
10-MAR-13
(There's more data on each line there but I am just showing a simplified example).
I know I can OR search with | character so find, JAN|FEB|MAR... but how do I replace according to what's found.
(Just trying to save some time)
Thanks.
Not sure if it's a plugin or built-in, but you can use the TextFX Characters plugin, to select the text, and then in the textfx characters dropdown, click UPPER CASE.
Update
Looks like it is a plugin:
TextFX menu is missing in Notepad++
Multiple Files
I found this site which gives a way to convert text to uppercase with regular expressions: http://vim.wikia.com/wiki/Changing_case_with_regular_expressions
So, what you can do is bring up the find in files dialog (CTRL+SHIFT+F), change search mode to Regular Expression, and then use something like this:
Find: (\d{2}-\w{3}-\d{2})
Replace with: \U\1
Directory: Whichever directory your files are in (and only the files you want changed).
\U is an uppercase flag, and the brackets in the Find regex correspond with the \1 backreference, which will basically replace it with itself (but uppercase).

Vim - Select text in between parentheses, multiline

value(val_1)
value(val_100)
value(val_10)
I want to select text between parentheses and do it for multiline, for one line I can use f(va( but I don't know how to select for 2 remaining lines.
EDIT (SOLUTIONS)
What I want to is to change text inside parentheses with unique text every line, firstly, I was thinking to select the text, delete it then change the text manually, #rosipov tell there is a plugin to do the selection part and it's great, but #romainl gave me another direction that works too.
f(ci(foo<Esc>jci(bar<Esc>jci(baz<Esc>
Do you want to select this:
value([val_1])
value([val_100])
value([val_10])
or to select that:
value([val_1)]
[value(val_100)]
[value(val_10])
The first is unfortunately not doable. But depending on what you want to do with the selected text, change it for example, a reasonable approximation would be:
f(l<C-v>jj$cnew value)<Esc>
However I'm sure a lot of Vimmers would probably approach the problem with a substitution:
:,+2s/(.*/(new value)
The second is done simply with:
f(lv3/)h
or
f(ljjt)
You will probably be interested in EasyMotion plugin in this case: https://github.com/Lokaltog/vim-easymotion
With plugin it will be: f(vLeaderLeaderf)c
Or: LeaderLeaderf(avLeaderLeaderf)c
Where c is letter representing 3rd closing parentheses, a represents first opening p.
EDIT: Without plugin it is possible to do it by line number.
Assuming that you work with lines 1-3: f(v3Gf)
Where 3G stands for "go to line number 3", works in both visual and normal modes.

Delete anything other than pattern

Let's say this is my text:
this is my text this
is my text this is my text
my text is this
I would like to highlight all text except pattern and delete the highlighted text.
p.e. text: this must be the result.
text
texttext
text
I've found the code how to select all text except pattern:
\%(\%(.{-}\)\#!text\zs\)*
however I don't know how to delete all highlighted text.
This doesn't work:
:%s/\%(\%(.{-}\)\#!bell\zs\)*//
Can anyone help me?
Try this:
:%s/\(^\|\(text\)\#<=\).\{-}\($\|text\)\#=//g
Explanation:
\(^\|\(text\)\#<=\) # means start of line, or some point preceded by “text”
.\{-} # as few characters as possible
\($\|text\)\#= # without globbing characters, checking that we reached either end of line or occurrence of “text”.
Another way to do it:
Create a function that count matches of a pattern in a string (see :help match() to help you design that)
Use: :%s/.*/\=repeat('text', matchcount('text', submatch(0)))
Forgive me, because I'm not a vim expert, but wouldn't prepending the search with v find the inverse so that you could do something like this?
:v/pattern/d
I've implemented Benoit's clever regular expression as a custom :DeleteExcept command in my PatternsOnText plugin. It offers other related commands like :SubstituteExcept or :SubstituteInSearch, too.
OP's example would be
:%DeleteExcept /text/
Comparing that with #Benoit's explicit command (:%s/\(^\|\(text\)\#<=\).\{-}\($\|text\)\#=//g), it's a lot simpler.

Resources