Multiline column copy paste in VS Code - visual-studio-code

Is it possible to do pasting in multiline editing (cursor |):
text1 = [|]
text2 = [|]
text3 = [|]
text4 = [|]
Assuming I have pasted the following lines:
val1
val2
val3
val4
I would like to have this result:
text1 = [val1]
text2 = [val2]
text3 = [val3]
text4 = [val4]
What actually happens is that the clipboard content is pasted four times, once for each cursor.
Something like mentioned in this answer, but instead of typing simply pasting: https://stackoverflow.com/a/30039968/1374488

Use column-edit instead of the multi-line edit mode:
Click the end of the source text.
Shift Alt, click the beginning.
Copy.
Click the end of the destination text.
Shift Alt, click the beginning.
Paste.

I had some trouble with this until I figured it out. The second selection ( where you want to paste ), must be the same length as the first selection, otherwise it pastes all items at each location ( instead of one item per row ).

1-select column of data you want to copy by holding alt+shift+mouse selection box and copy it with ctrl+c
2- select the places you want to paste into with alt+mouse click(note: this helps if the lines to be pasted into are in different places)
3-paste into the selected locations with ctrl+v

I had to do this for hundreds of lines, mapping db columns.
What I ended up doing to speed this is was creating an excel sheet with 3 columns:
COL1 COL2 COL3
text1 = [ val1 ]
text2 = [ val2 ]
text3 = [ val3 ]
text4 = [ val4 ]
And then searching and replacing tabs.

Worked for me https://github.com/john-guo/columnpaste . Adds Column paste command.

Related

Randomly choose 1 text-line from each of 3 lists of text-lines but instead it brings 3 blank text-lines

I have this code to randomly choose one line of text from each of the three lists of text lines within the same file, and copy them together to the clipboard.
It works but not properly because it brings three blank lines instead of three actual text lines.
It seems to me that the issue may be in the way this code is copying the text lines, but I'm not an expert.
Can somebody help me find where the issue is and maybe code it properly to bring the actual text lines instead of the blank ones?
My AutoHotkey is version 1.1.36.02 . Thanks in advance to everyone.
Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4
; Definining 3 lists of text lines:
list1 = 1st text line, 2nd text line, 3rd text line, 4th text line
list2 = 5th text line, 6th text line, 7th text line, 8th text line
list3 = 9th text line, 10th text line, 11th text line, 12th text line
; Selecting randomly one text line from each list:
selectedLine1 := list1[rand1]
selectedLine2 := list2[rand2]
selectedLine3 := list3[rand3]
; Concatenating the 3 selected text lines and copy them to the clipboard:
clipboard = %selectedLine1% `n %selectedLine2% `n %selectedLine3%
; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%
This solves the problem:
Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4
; Definining 3 lists of text lines:
list1 = 1st text line, 2nd text line, 3rd text line, 4th text line
list2 = 5th text line, 6th text line, 7th text line, 8th text line
list3 = 9th text line, 10th text line, 11th text line, 12th text line
; Selecting randomly one text line from each list:
selectedLine1 := strsplit(list1,",")[rand1]
selectedLine2 := strsplit(list2,",")[rand2]
selectedLine3 := strsplit(list3,",")[rand3]
; Concatenating the 3 selected text lines and copy them to the clipboard:
clipboard = %selectedLine1% `n %selectedLine2% `n %selectedLine3%
; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%

How to limit sed change to first set [duplicate]

This question already has answers here:
How to use sed to replace only the first occurrence in a file?
(25 answers)
Closed 6 years ago.
I have a text file that contains entries shown below.
tag1start
text1
text2
text3
text4
tag1end
..
..
tag1start
text5
text6
text7
text8
tag1end
I need to change entries only in the first set of tag1start tag1end
I have attempted using "range" but it affects both the sets. How do I limit it only to the first set ?
/tag1start/,/tag1end/c\
Some other text1\
Some other text2\
Some other text3\
Some other text4\
Some other text5\
Some other text6\
tag1end
sed '/tag1end/,$!{1,/tag1start/!s/\(.*\)/Some other \1\\/;}'
Roughly translated: In all except the part from tag1end to the last line (which, being greedy, is everything after the first tag1end), do the following: in all except the part from line 1 to tag1start, turn foo into Some other foo\.
Consider:
$ sed '/tag1end/,${p;d}; /tag1start/,/tag1end/{s/^/Some other /}' file
Some other tag1start
Some other text1
Some other text2
Some other text3
Some other text4
tag1end
..
..
tag1start
text5
text6
text7
text8
tag1end
How it works
/tag1end/,${p;d}
For all lines in the range from the first line matching tag1end to the end, $, print the line as it is (p) and start over with the next line (d).
/tag1start/,/tag1end/{s/^/Some other /}
We only get to this command if we have not yet reached the first tag1end. If we have not yet reached tag1end and we are in the range /tag1start/,/tag1end/, then the commands in curly braces are performed. You can put whatever sed commands you like in those braces.

Inserting blank spaces at the end of a column name in a table using pander

I am trying to find a way of centering a column heading in a pander table using knitr to pdf in rmarkdwon, but keeping the column entries right justified.
---
title: "Table Doc"
output: pdf_document
---
```{r table, echo = FALSE}
table1 <- anova(lm(Petal.Length ~ Species*Petal.Width, iris))
names(table1) <- c("DF", "Sum Sq", "Mean Sq", "*F*", "*p*")
library(pander)
pander(table1, justify = c("left", rep("right", 5)))
```
There is no way to align individual cells inside a table in pandoc apparently. I want the entries to be to the right so they are all aligned properly but sit the column headings 'F' and 'p' in the center. So what I need to do is insert blank spaces after F and p to force them into the center. How do I do this? I tried simply inserting the blank spaces:
names(table1) <- c("DF", "Sum Sq", "Mean Sq", "*F* ", "*p* ")
but the spaces are not recognised by pander.
I also tried LaTex spacing characters
names(table1) <- c("DF", "Sum Sq", "Mean Sq", "*F*\\", "*p*\\")
but this didn't work either. Can anyone think of a workaround?

Applescript to resort piles of numbers

I'm trying to resort a bunch of numbers with Applescript. I'm very new to the language and I thought I'd ask you for help.
I have a group of numbers which looks like this in my TextEdit file:
v 0.186472 0.578063 1.566364
v -0.186472 0.578063 1.566364
v 0.335649 0.578063 1.771483
What i need is a script that resorts these numbers, making it appear like this:
(0.186472, 0.578063, 1.566364),
(-0.186472, 0.578063, 1.566364),
(0.335649, 0.578063, 1.771483),
So after each number, there has to be a comma, and always the three numbers on one line have to be put into brackets (). finally there has to be another comma after every bracketed group of three and the v before every line has to be deleted.
I've only so far managed to get rid of every "v" using:
set stringToFind to "v"
set stringToReplace to ""
But now im stuck and I'm hoping for help.
To find and replace strings in AppleScript the native way is using text item delimiters. There are a fixed number of values separated by spaces (or tabs) on each line, using text item delimiters, text itemsand string concatenation we can solve your problem.
I've added an addition linefeed in front and at the back of the string to show that lines that doesn't contain 4 words are ignored.
set theString to "
v 0.186472 0.578063 1.566364
v -0.186472 0.578063 1.566364
v 0.335649 0.578063 1.771483
"
set theLines to paragraphs of theString
set oldTIDs to AppleScript's text item delimiters
repeat with i from 1 to count theLines
set AppleScript's text item delimiters to {space, tab}
if (count of text items of item i of theLines) = 4 then
set theNumbers to text items 2 thru -1 of item i of theLines
set AppleScript's text item delimiters to ", "
set item i of theLines to "(" & (theNumbers as string) & "),"
else
set item i of theLines to missing value
end if
end repeat
set theLines to text of theLines
set AppleScript's text item delimiters to linefeed
set newString to theLines as string
set AppleScript's text item delimiters to oldTIDs
return newString

Displaying text from two fields, separated by a varying number of "." symbols, while preserving the total string length

I'm trying to create a Table of Contents for a small publication using Filemaker 10, since that's what the data has been stored in previously.
I'm able to generate page numbers, add heading to the TOC and pretty much everything else I've needed to do - one thing withstanding.
Our designer wants to fill each TOC line with "." to make it easier to read.
Currently:
Using Stack Overflow 1
Why Reddit is better than digg 7
Does Filemaker really suck this much 84
Ways to convince bosses 92
Ditching FileMaker 97
Wanted:
Using Stack Overflow..................................................1
Why Reddit is better than digg........................................7
Does Filemaker really suck this much.................................84
Ways to convince bosses..............................................92
Ditching FileMaker...................................................97
The item and page number are in different fields. Using a border is unsatisfactory because it underlines everything.
Solutions?
You can do this using tab stops in the Format -> Text menu
1) Create a calc field with the following definition (the character in the quotes is a tab):
title & " " & page
2) Add this field to your layout (it needs to be an actual field, not a merge field)
3) Highlight the field and choose format -> text -> paragraph -> tabs
4) Create a new Tab with a position of 6 inches and a Fill Character of "." or "…"
Now when viewed, any space from the end of the title up to the tab stop 6 inches away is filled with the fill character. No monospace font required.
You need to break it up into bits and then put it back with the right spacing. Something like this would do :
Let ( [
text = "Why Reddit is better than digg........................................7" ;
len = Length ( text ) ;
end = RightWords ( text ; 1 ) ;
lenEnd = Length ( end ) ;
lenStart = Length ( Trim ( Right ( text ; len - lenEnd ) ) ) ] ;
Left ( text ; lenStart ) &
Left ( "..........................................................................." ; len - lenStart - lenEnd ) &
end )
I've built the "text" variable into the calc for testing, but you could do this as a Custom Function or just inside a calculation with the field instead.
Also this assumes you're using a mono spaced font and the gap in the middle is a space character.