Pasting data in multiple cursor mode - visual-studio-code

in vs code I have the following file
1
2
3
a
b
c
Now I do the following steps
cut the lines a b c.
select the lines 1, 2, 3 and then go into multiple cursor mode (shift, alt I).
go to the end of the each number press and type a , and then do a paste.
The result is
1, a
b
c
2, a
b
c
3, a
b
c
but the result I wanted is
1, a
2, b
3, c

Check out Mark's good answer as well. There have been some updates to VS Code he mentions that should be considered as well.
Using Shift+Alt+I, you need to cut the text in multiple cursor mode as well:
1Enter2Enter3EnterEnteraEnterbEnterc
Shift+↑↑
Shift+Alt+I
Shift+←
Ctrl+X
↑↑↑↑→
, 
Ctrl+V
As of the 1.23.1 April update, a more convenient, middle mouse button selection can be used.
With the cursor and keyboard,
Instead of cutting the lines like normal, select from the end of the cursor to the beginning while in multi-cursor mode while holding Ctrl+Shift. After cutting the text with Ctrl+X, select with multiple cursors again by holding Ctrl+Shift. Then, type ,  and paste with Ctrl+V like you described.
You can also use Ctrl+Alt+Shift and the direction arrows to select with multiple cursors,

Sometime ago this functionality was apparently added. You can simply cut to your clipboard and then paste to multiple cursors - and, if there are the same number of lines on the clipboard as multiple cursors - each cursor will get one line from the clipboard.
You no longer need to be in multi-cursor mode for the cut or however you got the text onto the clipboard.
Just cut it.
Demo:
Unfortunately, the gif cut off the full command after selecting the 1,2,3,. What you then want to do is put a cursor at the end of each line of the selection. Command: Add Cursors to Line Ends Shift+Alt+I.
VSCode 1.39 added this setting:
Editor: Multi Cursor Paste
Controls pasting when the line count of the pasted text matches the
cursor count.
"editor.multiCursorPaste": "spread"
that will do what you want.
There is a second option full where each cursor will get the entire clipboard text. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_39.md#new-option-for-multi-cursor-pasting. Demo of the full option:
From the multi-cursor paste release notes:
New option for multi cursor pasting
In the past, when pasting multi-line text from the clipboard, VS Code
would check if the clipboard text line count matches the cursor count,
and if it does, it would "distribute"/"spread" each line to a cursor.
This behavior is now tunable via the editor.multiCursorPaste setting,
which can have the values:
spread - Each cursor pastes a line of text (default).
full - Each cursor pastes the full clipboard text.

Related

Select multiple lines with cursors at each line start

I want to select multiple lines and put a cursor at the beginning of each line. Sublime Text can do this with Ctrl-Shift-L
select multiple lines
ctrl + shift + L and then put cursor at beginning of each line
Press Crtl + Shift + Alt + Arrow up/down to select multiple lines in Visual Studio Code. Note that the selected lines will be in one column (if possible).
You can also mark some lines and then do this combination and you have all selected lines included.
Moreover you can press and hold Alt and click the lines you need. This way you can select multiple lines that are not neighbours or in the same column.
To do exactly what Ctrl-Shift-L does in Sublime Text, you must do:
On Windows:
Select the lines.
Alt-Shift-I (will add multiple cursors)
Shift-Home (will go at the beginning of each line and be selected)
On Mac :
Select the lines.
alt-shift-I (will add multiple cursors)
cmd-shift-←
(will go at the beginning of each line and be selected)
More information in this answer.
Put cursor at beginning of first line
Ctrl-Shift-Alt-Arrow down/up will put a cursor at the beginning of the following/preceding lines
Ctrl-I will select those lines with the cursor at the beginning of each line.
NOTE : On my vscode the cursors look like they might be shifted down one line but they actually are not - the are in the right place. If you start typing, it works but you have to hit Enter when you are done to get back separate lines. It is a little quirky but works as you would expect.
EDIT (using a hint from #Maxime's answer)
Select your test first.
Alt-Shift-I : puts cursors at the end of each of those lines but text unselected (I as in island not a lowercase L)
Function-Home : put cursors at beginning of each line.
Ctrl-I : selects all lines.
Important: read the NOTE above.
--------------------- v1.43 see How to put the cursor at the end of all selected lines in Visual Studio Code? with column selection mode it is easy to put the cursor at the beginning or end of lines selected by dragging.
You can hold alt and click the places you need with the mouse. This way you can select rows that aren't related, like row 10,15,18. Also you can select at different places in the same row.
I hope this helps someone, but there is a setting in VSCode called Editor: Multi Cursor Modifier which may do what OP is asking:

How to select every N line in vscode?

How can I select every N lines in visual studio code.
I can't find a proper regualr expression can let me do this.
Press Ctrl+F or command+F.
If not already enabled, press Alt+R or option+command+R to toggle RegEx searching (or press the .* button).
Enter (.*\n){N} into the search field, replacing N with the number of lines to select (such as (.*\n){2} for every second line).
Press Alt+Enter or option+return or Select All Occurrences of find Match from the command palette to select every Nth grouped lines.
Press ← to place the cursor at the beginning of every Nth line, or → then ← to place the cursor at the end of every Nth line.
Ctrl+H
Check the regex icon .*
Search: (^.*?$[\n]){9}
That RegExp will find [ed. but not select] 9 lines of code at a time - empty lines do count as a line.
What are you going to replace them with?
If you want to replace every nth line, like every 9th line with some new text, try this regex:
((.*\n){8})(.*\n)
and replace with $1[new line 9 stuff here]
Select Multi lines in VsCode
Visual code natively supports this functionality.
But you have to select the lines manually.
Hold the alt button and click where you want to select the data
You can also select multiple lines
For more details:Visual Studio Code Documentation

How do I get a cursor on every line in vscode

I'm trying to use the multi cursor functionality of vscode on a large(ish) file.
the file is too large to select every line individually with ctrl-alt-up or down. In sublime-text I would select everything and push ctrl-shift-l. Is there a similar thing in vscode. I've tried using a regex search for ^, but that gives me an error stating "Expression matches everything".
The command Selection / Add Cursors to Line Ends altshifti will put a cursor on every line in the current selection. (For mac use optshifti)
Tip: You can pull up the keyboard shortcut reference sheet with ctrlk,ctrls (as in, those two keyboard combos in sequence).
(For mac use cmdk,cmds)
Hold Alt+Shift and select the block. Then press End or Right button.
You get selected individual lines.
I use version VSCode 1.5.3 in Windows.
Hold Alt+Shift+i
Hold Home (fn+-> Mac) for right-most or End for left most(fn+<- Mac)
This feature is actually called split selection into lines in many editors.
Sublime Text uses the default keybinding, CTRLSHIFT L
VSCode uses ALTSHIFTI
For Atom you actually need to edit your keymap to something like this
'.platform-win32 .editor, .platform-linux .editor':
'ctrl-shift-L': 'editor:split-selections-into-lines'
Real Lines vs Display Lines
First we have to understand the difference between Real Lines and Display Lines to completely understand the answer of the question.
When Word Wrap is enabled, each line of text that exceeds the width of the window will display as wrapped. As a result, a single line in the file may be represented by multiple lines on the display.
The easiest way to tell the difference between Real Lines and Display Lines is by looking at the line number in the left margin of the text editor. Lines that begin with a number correspond to the real lines, which may span one or more display lines. Each time a line is wrapped to fit inside the window, it begins without a line number.
Cursor At the Beginning of each Display Lines:
Cursor At the Beginning of each Real Lines:
Answer to the Question
Now that we know the difference between Display Lines and Real Lines, we can now properly answer the actual question.
Hold AltShift and select the text block.
Press Home to put cursor on the beginning of every Display Line.
Press End to put cursor on the end of every Display Line.
Press HomeHome (Home twice) to put cursor on the beginning of every Real Line.
Press EndEnd (End twice) to put cursor on the end of every Real Line.
Please understand that AltShiftI put cursor on the end of every Real Line.
Install the extension Sublime Commands.
[Sublime Commands] Adds commands from Sublime Text to VS Code: Transpose, Expand Selection to Line, Split into Lines, Join Lines.
(Don't forget to add the keybinding(s) from the extensions details page to your keybindings.json)
Doesn't VS Code already have a "split into lines" command?
Yes, yes it does. However it differs from the one in Sublime.
In VS Code, when you split into lines your selection gets deselected and a cursor appears at the end of each line that was selected (except for the last line where the cursor appears at the end of the selection).
In Sublime, when you split into lines a cursor appears at the end of each line (with the same exception as in VS Code) and the selection is divided on each line and "given" to the same line.
I have the same problem, i'm used to Alt + drag to do 'box selections' in visual studio but it does'n work in code.
It seems to be impossible for now to do it differently than by selecting every single line.
However plugins should be supported soon so we will likely see a plugin for this if not implemented directly by microsoft.
From visual studio uservoice forums:
We plan to offer plugin support for Visual Studio Code. Thank you for your interests and look for more details in our blog in the coming weeks. http://blogs.msdn.com/b/vscode.
For the preview we are looking for exactly this type of feedback. Keep it coming.
Sean McBreen – VS Code Team Member

Copy Lines including carriage return linefeed in notepad++

Using Notepad++ I want to select individual, non-contiguous lines, copy them, and past them and include the CR/LF at the end. Preferrably, I would hold Ctrl, then click the line numbers I want, then press Ctrl+C or right click and select copy; however doing this selects all text (which is frustrating and doesn't make much sense). Furthermore, only selecting the line partially includes the line below it, so that if i press Ctrl+Shift+Up(or down) the line below it also moves up or down.
In summary, I want to copy non-contiguous lines and past them with their respective EOL characters.
Use Ctrl+F2 to mark desired lines.
Menu Search > Bookmarks > Copy bookmarked lines will copy these lines into clipboard.
As option for step 1, you can use Mark tab of Find dialog (Ctrl+F) with Mark Line option checked.

Can I make a macro in n++ that does a search/replace?

I'm new to n++, but I have been most impressed with this tool so far. I've been trying to record a macro that do a search/replace, but the 'search' part seems to have the initial search text from the recording 'hard-coded' in the macro.
What I want is:
Manually locate the cursor at the beginning of the first line of a fixed format code segment, then Macro actions:
move cursor two lines down
move cursor right x characters
mark charters from pos x to x+n
search and replace all occurrences of the selected text with "{p_'selected text'}"
In an more advanced version, I'd like to add some logic to step 4: only execute the replace part if the # of occurrences are > 1 (e.g. by first adding a count statement, but I'm not sure how to obtain the returned count # from the dialog box)
Is this possible?
While I'm a big fan of Notepad++, this sounds like something I would accomplish with AutoHotKey. You would select the text and copy it to the clipboard. AutoHotKey would read the clipboard, replace the text as you desire, and either replace the clipboard contents, or send it back to your document. Let me know if you would like to go that route.