How to edit all line in Visual Studio Code

2020-02-19 17:24发布

问题:

I have a list of data that 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

abcde
cdeab
deabc
eabcd

And I want all the line to look like

'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!

回答1:

You could edit and replace with a regex:

Find (Ctrl+F):

^(.+)$

Replace:

'$1'

This regex finds any content on a line and inserts it inside quotes. Be sure to tick the regex icon.

If every line might have a space before the content, try this:

Find:

^ ?(.+)$

Replace:

 '$1'


回答2:

You can use the Alt + Shift shortcut.

  1. First press Alt + Shift then click the mouse button on the first line.

  2. Go to the last line, and then do the same.

This will mark all the parts of one side. Whatever you type will be reflected in the marked spaces.

Do the same on the other side too.



回答3:

Use Toggle Multi curosr Modified from action pane.

Select the cursor points with ctrl + <Mouse click> , you can modify everything simultaneously.

This will require lots of manual efforts if lines are more



回答4:

You can use Find and Replace.

Besides, paste to Excel and using a function to add character '.



回答5:

The first thing that came to my mind - replace abcde with 'abcde' line by using option Find and Replace option. I'm pretty sure Visual Studio Code has something similar to that.



回答6:

1- You can use the Ctrl + H shortcut (menu EditReplace)

  1. Enter abcde in Find Control.

  2. Enter 'abcde' in Replace Control.

  3. Then press Ctrl + Alt + Enter.