Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 981
Charlez Kwan Tsz Shun Avatar asked Jun 01 '17 14:06

Charlez Kwan Tsz Shun


People also ask

How do you edit all lines at once VSCode?

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


3 Answers

  1. Press Ctrl+F or command+F.
  2. If not already enabled, press Alt+R or option+command+R to toggle RegEx searching (or press the .* button).
  3. Enter (.*\n){N} into the search field, replacing N with the number of lines to select (such as (.*\n){2} for every second line).
  4. Press Alt+Enter or option+return or Select All Occurrences of find Match from the command palette to select every Nth line.

enter image description here

like image 168
Daniel Avatar answered Oct 19 '22 13:10

Daniel


  • 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]

like image 38
Mark Avatar answered Oct 19 '22 12:10

Mark


Select Multi lines in VsCode

Visual code natively supports this functionality.

But you have to select the lines manually.

  1. Hold the alt button and click where you want to select the data

enter image description here

  1. You can also select multiple lines enter image description here

For more details:Visual Studio Code Documentation

like image 10
Hamza Anis Avatar answered Oct 19 '22 14:10

Hamza Anis