How to select every N line in vscode?

Charlez Kwan Tsz Shun picture Charlez Kwan Tsz Shun · Jun 1, 2017 · Viewed 10.5k times · Source

How can I select every N lines in visual studio code. I can't find a proper regualr expression can let me do this.

Answer

Mark picture Mark · Jun 2, 2017
  • 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]