IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Add Comma to Each Line Using Visual Studio Code or Sublime Text

Sometimes the simplest thing is really taken for granted and we take the long route to do the simplest thing. We received a CSV with thousands of ID numbers that will be used to update a database table. The data would look like the following:

  87295
  86719
  31695
  94836
  17957
  69783
  57168
  96874
  12853
  92816
  ...
  [deleted for brevity]
  ...

Open a text file in Visual Studio Code

The goal is just to add a comma at the end of each line so it can be used to update data in a database table.

In the past, we would probably write a macro module in Excel, but other than a security risk, it’s overcomplicating a simple task.

Using either Visual Studio Code or Sublime Text, we can accomplish this task in a matter of seconds. No writing macros required.

1. Use the Search and Replace Control

This works the same way in both Visual Studio Code and Sublime Text. The only difference is the shortcuts between PC and Mac.

PC

  1. Press CTRL+H for Replace.
  2. Type in $ in Find, and , in Replace.
  3. Make sure Regular Expression is turned on (ALT+R)
  4. Replace All by pressing CTRL+ALT+ENTER.

Mac

  1. Press Option+Command+F for Replace.
  2. Type in $ in Find, and , in Replace.
  3. Make sure Regular Expression is turned on (Option+Command+R)
  4. Replace All by pressing Option+Command+ENTER.

Visual Studio Code Search and Replace All with Regex

2. Use Multi-Line Editing

Visual Studio Code

  1. Select all by pressing CTRL+A (or Command+A for Mac).
  2. From Selection, choose Add Cursors to Line Ends by pressing SHIFT+ALT+I (or SHIFT+OPTION+I).
  3. Type the Comma character.

Visual Studio Code Selection Add Cursors to Line Ends

Sublime Text

  1. Select all by pressing CTRL+A (or Command+A for Mac).
  2. From Selection, choose Split into Lines by pressing CTRL+SHIFT+L (or COMMAND+SHIFT+L).
  3. Move the cursors at the end of lines by pressing End on Windows or Right Arrow on macOS.
  4. Type the Comma character.

Whatever method you use, the end result will look like the following:

Text file with commas in Visual Studio Code

Further Reading

How to Reassign Shortcut Key for Column Selection in Visual Studio Code
How to Reassign Column Selection Shortcut Keys in Sublime Text
Adding Comma to Each Line Using Sublime Text 2
How to Open Visual Studio Code from command line macOS

October 5, 2021 Filed Under: How To Tagged With: Code Editor, Sublime Text, Visual Studio Code

How to Reassign Column Selection Shortcut Keys in Sublime Text

Following the previous post on assigning a new keyboard shortcuts for column selection, this time we’re going to the same thing in Sublime Text.

As always, before you make any changes, make sure you backup everything.

macOS (OSX)

On the top menu, click on Sublime Text -> Preferences -> Key Bindings and a split screen will open.

Sublime Text Preferences Key Bindings

Sublime Text User Keymap

Using the same key combination as in the example provided for Visual Studio Code (SHIFT-ALT-ARROW), you can paste the following javascript code on the right pane (User). If you’ve already had other custom keybindings, you want to add the two lines without the square brackets in the beginning and end of the code block.

Default (OSX).Sublime-keymap — User

[
    { "keys": ["shift+alt+up"], "command": "select_lines", "args": {"forward": false} },
    { "keys": ["shift+alt+down"], "command": "select_lines", "args": {"forward": true} },
]

Windows

On Windows version of Sublime Text, you can click directly on Preferences -> Key Bindings from the top menu and apply the same treatment as above (copy and paste the JSON above to the right-pane of the split screen).

Sublime Text Preferences Key Bindings on Windows

Closing Thought

Personally, custom key binding especially for column selection has helped me to use both Visual Studio Code and Sublime Text without requiring me to make too much mental switch on either Windows or Mac.

Another trick you may want to try is to use a similar key placement instead of the literal key combination instead. What I mean by this is that the position of ALT key in Windows and Mac is a bit different. The ALT key on Windows is on the same position as Command (⌘) key on Mac.

So I set my Mac column selection key binding a bit different than its Windows counterpart (alt is replaced with command instead).

[
    { "keys": ["shift+command+up"], "command": "select_lines", "args": {"forward": false} },
    { "keys": ["shift+command+down"], "command": "select_lines", "args": {"forward": true} },
]

Related Article

How to Reassign Shortcut Key for Column Selection in Visual Studio Code
How to Add Comma to Each Line Using Visual Studio Code or Sublime Text

August 12, 2017 Filed Under: How To Tagged With: Code Editor, Sublime Text

How to Use Your Favorite Text Editor in Git

After installing Git and initially configuring it, you can further configure it to use your favorite text editor as the default. What you need to do is set the value of core.editor to the program file of your editor and add a flag -w at the end. The -w basically is to tell Git to wait until all operations within the text editor is done before Git can continue to do its thing afterwards.

Windows

git config --global core.editor '"C:\Program Files\Sublime Text 4\sublime_text.exe" -w'

Pay attention to the placement of single quote (‘) and double quotes (“). You want to enclose the whole path of your editor within the quotes, then wrap the whole argument with the flag with the other.

You can use single quote or double quotes interchangeably as long as they’re consistent
(i.e., "'C:\Program Files\Sublime Text 4\sublime_text.exe' -w" works the same way as in the example above).

macOS / Linux

git config --global core.editor "subl -n -w"

Now, if you want to see if the text editor is set correctly, just type in this command:

git config --global --list

And you should see the core.editor value listed to look like this:
Git config --global --list command

Sublime Text is used as an example just because it’s available on Windows, OSX, and Linux. You can certainly substitute the path or program name with whatever text editor you have.

Using Visual Studio Code

Update 9/27/2021: If you use Visual Studio Code as your main editor, the setup is even more simple and this is actually is the more recommended setup now since this post was published (Visual Studio Code can be downloaded from the link at the bottom of this post).

You just need to type the following:

git config --global core.editor "code -w"

If you use macOS, before this configuration can work, you need to setup Visual Studio Code so it can be called from the command line. Then the Git setup to use it is the same on both Windows and macOS.

Further Reading

How to Open Visual Studio Code from command line macOS
How to Enable Font Ligatures in Visual Studio Code
How to Install Git
Basic Configuration in Git

Download

Visual Studio Code
Git

October 1, 2014 Filed Under: How To Tagged With: Code Editor, Git, Sublime Text, Visual Studio Code

How to Install Sublime Text in Linux

Sublime Text 2 This short tutorial is based on the link provided on the bottom of this post with slight modifications. The example is shown with 64-bit version of Linux Mint.

Download Sublime Text

Open your browser and go to Sublime Text and download the file to directory Downloads.

Setup

Open Terminal and type in the following command:

cd ~/Downloads

Then type in this command to extract the file:

tar -jxvf "Sublime Text 2.0.1 x64.tar.bz2"

Once the file is extracted, type the following commands individually:

sudo mv "Sublime Text 2" /opt/sublime/

sudo chown -R root:root /opt/sublime

sudo chmod -R +r /opt/sublime

Create a Sublime Text Executable

Execute the following commands to create a Sublime Text executable in your path:

sudo touch /usr/bin/sublime_text

sudo chmod 777 /usr/bin/sublime_text

Launch Pluma Text Editor by typing ALT+F2 (RUN) and enter this command:

gksu pluma /usr/bin/sublime_text

Copy & paste the code below:

#!/bin/sh
export SUBLIME_HOME="/opt/sublime"
$SUBLIME_HOME/sublime_text "$*"

Pluma Text Editor Sublime Text 2

Save the file and exit.

Next, type in this command:

sudo chmod 755 /usr/bin/sublime_text

Create a Menu Icon

Launch the default text editor (Pluma) again by typing Alt+F2 and type in:

gksu pluma /usr/share/applications/sublime.desktop

Copy & paste the code below:

[Desktop Entry]
Encoding=UTF-8
Name=Sublime Text 2
Comment=Edit text, code and markup
Exec=sublime_text
Icon=/opt/sublime/Icon/256x256/sublime_text.png
Terminal=false
Type=Application
Categories=GNOME;GTK;Utility;TextEditor;
StartupNotify=true

Pluma Text Editor Sublime Text Desktop

That’s it. If you go to the Menu, you should see Sublime Text 2 under the Applications, Accessories.
Sublime Text 2 in Linux Mint Applications Menu

Download

Sublime Text

Further Reading

Install Sublime text editor

June 2, 2013 Filed Under: How To Tagged With: Code Editor, Linux, Sublime Text

Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure