skip to Main Content

In Notepad++, you can Alt-LeftClick to select a vertical insert point over a series of lines, and then start typing. When doing so, Notepad++ will automatically insert as many spaces as it needs to on each line to pad up to your insertion point before inserting the typed characters.

Is there a way to do this in VSCode?

I work on a legacy code base where the "blame" number is required to be placed at column 73 on each line. e.g.:

From this:

IIF NOT RAINNG  $
  THEN                            
    PLAYFB      $
  ELSE  '' If it is raining ''    
    PLAYBG      $
  ENDIF   '' IIF NOT RAINNG ''    

to this:

IIF NOT RAINNG  $                 ''If it's not raining             ''111111
  THEN                                                                111111
    PLAYFB      $                 ''  Go play football              ''111111
  ELSE                            ''If it is raining                ''111111
    PLAYBG      $                 ''  Play a board game             ''111111
  ENDIF   '' IIF NOT RAINNG ''                                        111111

So it’s a drag to have to manually put in spaces or tabs to get to the correct column on every line. Notepad++ made this simple, but I’m trying to switch over to VSCode because of its superior capabilities and extensibility.

Note, this is not a duplicate of Can I make VSCode column mode like Notepadd++?.

2

Answers


  1. Chosen as BEST ANSWER

    Found an extension called Cursor Align which does what I need, at least pretty close.


  2. In VSCode, you can achieve a similar result to Notepad++’s vertical insertion with a few steps. While VSCode doesn’t natively support automatic padding like Notepad++, there are methods to help you align your text more easily.

    Here are a couple of approaches you can use:

    1. Multi-Cursor Editing
      Select the lines where you want to add the blame numbers.
      Use Alt + Click to create a cursor at the desired column (73) on each line.
      Start typing, and you’ll see the text inserted at each cursor position.
      However, this method won’t automatically add spaces to align to column 73; you’ll need to manually adjust the spacing afterward.

    2. Using Extensions
      You can use an extension that helps with column editing or formatting:

    "Align" Extension:
    Install the Align extension.
    Highlight the lines you want to align, and use the command palette (Ctrl + Shift + P) to find and run the "Align" command, which allows you to align text based on a delimiter or spaces.
    3. Regular Expressions
    You can also use Find and Replace with regular expressions to quickly add spaces:

    Open the Find and Replace panel (Ctrl + H).
    Enable regular expressions (the .* icon).
    In the "Find" box, enter ^(.*)$ to match every line.
    In the "Replace" box, enter $1 followed by the appropriate number of spaces (to reach column 73).
    Click "Replace All".
    You may need to calculate how many spaces to add based on the length of the current line.

    1. Using Snippets
      If you find yourself frequently adding the same blame number, consider creating a snippet:

    Go to File > Preferences > User Snippets.
    Select or create a snippet file for your language.
    Define a snippet that includes the blame number at the correct column.
    Example Snippet
    json
    Copy code
    "Insert Blame Number": {
    "prefix": "blame",
    "body": [
    "${1:Text here}${2: }${3:111111}"
    ],
    "description": "Insert blame number with padding"
    }
    You can trigger this snippet by typing blame followed by pressing Tab.

    Conclusion
    While VSCode doesn’t replicate Notepad++’s automatic padding feature directly, these methods should help you manage alignment and insertion effectively. Combining multi-cursor editing with some regex find-and-replace should get you pretty close to what you need.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search