Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit all lines in Visual Studio Code

I have a list of data to which I need to put a ' symbol at the start of the line and at the end of the line. So the original data looks like this:

abcde cdeab deabc eabcd 

And I want all of the lines to look like this:

'abcde' 'cdeab' 'deabc' 'eabcd' 

In my real data, I would have 10,000 of lines. So if I can do something like Ctrl+Shift+A to select the entire document and then have some magic shortcut to change from selecting all lines to editing all lines that would be perfect!

like image 530
Peak Sornpaisarn Avatar asked Jun 28 '17 04:06

Peak Sornpaisarn


People also ask

How do you edit multiple lines at once in VS code?

Select the lines you want and then press: Windows: Shift + Alt + i. Mac: shift + option + i.

How do you edit multiple lines in visual studio?

If you want to select multiple lines / edit multiple lines in non aligned blocks you need to press Ctrl+Alt and explicitly click where you want each cursor to be and then just start typing as in example 2 below.

How do you change everything in VS code?

Expand the Search widget to display the Replace text box. When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.

How do you select every line in Vscode?

Solution. Open the desired file and press CTRL + A to select all lines.


2 Answers

You could edit and replace with a regex:

Find (Ctrl+F):

^(.+)$ 

Replace:

'$1' 

This regex finds any content on a line and wraps it inside quotes. The $1 refers to whatever is matched inside the parentheses in the regex. In this case, it's "one or more characters" i.e. everything on the line. Be sure to tick the regex icon.

Video demonstration of the replacement

If every line may or may not have a space before the content, and you want every line to have a space, try this:

Find:

^ ?(.+)$ 

Replace (notice the space before the first quote):

 '$1' 
like image 107
cbr Avatar answered Sep 22 '22 15:09

cbr


Here is an easy way to do this:

  1. Ctrl+A to select all or select your desired text.

  2. Shift+Alt+I to put a cursor at the end of each line.

  3. Type your ' (or whatever you want at the end).

  4. Home will move all your cursors to the beginning of the lines.

  5. Type your ' (or whatever you want at the beginning of all the lines).

like image 34
Mark Avatar answered Sep 20 '22 15:09

Mark