0

Using an atomic procedure from Visual Studio Code or an extension (not multi-line cursor)

const db          = require('./lib/db'),
    path        = require('path'),
    fs          = require('fs'),
    Logger      = require('./lib/log.lib'),
    rfs         = require('rotating-file-stream'),
    morgan      = require('morgan'),
    mung        = require('express-mung'),
    compression = require('compression'),
    bodyParser  = require('body-parser');

into this

const db          = require('./lib/db');
const path        = require('path');
const fs          = require('fs');
const Logger      = require('./lib/log.lib');
const rfs         = require('rotating-file-stream');
const morgan      = require('morgan');
const mung        = require('express-mung');
const compression = require('compression');
const bodyParser  = require('body-parser');

?

andypopa
  • 536
  • 6
  • 15
  • Press `Alt` and click. You'll get multi-line cursor. – adiga Apr 23 '19 at 08:36
  • Possible duplicate of [Multiple cursors in Visual Studio Code](https://stackoverflow.com/questions/29953479/multiple-cursors-in-visual-studio-code) – adiga Apr 23 '19 at 08:37

1 Answers1

0

You could just do a find and replace with a regex.

Find: ^(const)*\s*(.*)[,;]$

Replace: const $2;

Select your text, click the Find in Selection option and replace all.

demo of regex replace working


Or put it into a snippet:

 {
    "key": "alt+4",           // whatever keybinding you wish
    "command":  "editor.action.insertSnippet",
    "args": {
      "snippet": "${TM_SELECTED_TEXT/\\s*(const)*\\s*(.*)[,;]/\tconst $2;\n/g}"
    },
    "when": "editorTextFocus && editorHasSelection"
  },

Select your text and trigger the snippet. you may have to indent them all some but they will be aligned.

Mark
  • 143,421
  • 24
  • 428
  • 436