How to wrap each line in quotes in SublimeText?

Sublimetext3Sublimetext

Sublimetext3 Problem Overview


Input:

boston beach summer figural yellow blue
boston floral flowers still still-life food pink figural
boston horse pink purple house flowers floral figural

Expected output:

"boston beach summer figural yellow blue"
"boston floral flowers still still-life food pink figural"
"boston horse pink purple house flowers floral figural"

The actual input file has 600+ lines, and I'm looking at a quick way to wrap each line in quotes? Does the method involve using multiple cursors? How about macros?

Sublimetext3 Solutions


Solution 1 - Sublimetext3

I would use a multiple cursors approach like this:

Windows

  1. Ctrl + A (Select everything)
  2. Ctrl + Shift + L (Split into lines)
  3. End (Put the cursor at the end of the line)
  4. " (Add the quote at the end of the line)
  5. Home (Go to the first character of the line)
  6. Home (Go to the beginning of the line... like if you have tabs or spaces)
  7. " (Add the quote at the beginning of the line)

Mac

  1. Cmd + A (Select everything)
  2. Cmd + Shift + L (Split into lines)
  3. Cmd + (Put the cursor at the end of the line)
  4. " (Add the quote at the end of the line)
  5. Cmd + (Go to the first character of the line)
  6. Cmd + (Go to the beginning of the line... like if you have tabs or spaces)
  7. " (Add the quote at the beginning of the line)

Solution 2 - Sublimetext3

Method 1:

  • no multiple cursors
  • + best performance (use for large files)
  • - slightly clumsy

Replace (.*) with "\1"

Method 2:

  • multiple cursors
  • + best in regards to usability/comfort
  • - slower for bigger files
  • - wont work if the file has empty lines

Ctrl+a, Ctrl+Shift+l, "

Method 3:

  • multiple cursors
  • + close to #2 as usability, but works always
  • - slower for bigger files

Ctrl+a, Ctrl+Shift+l, End, ", Home, "

Solution 3 - Sublimetext3

None of these worked in Sublime Text 3 for a multi-column TSV file with tab spacing.

I found this worked for column 1:

Find: ^\s*\S+
Replace: "$0"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAniket SuryavanshiView Question on Stackoverflow
Solution 1 - Sublimetext3MaximeView Answer on Stackoverflow
Solution 2 - Sublimetext3ndnenkovView Answer on Stackoverflow
Solution 3 - Sublimetext3gdwittView Answer on Stackoverflow