55

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?

Aniket Suryavanshi
  • 1,534
  • 3
  • 14
  • 23

3 Answers3

174

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)
Maxime
  • 8,645
  • 5
  • 50
  • 53
  • 2
    cool, but: how in the name of god I exit this multi cursor mode now?? – sscarduzio Jul 21 '16 at 16:17
  • 2
    Simply click somewhere else. Or use the arrows to go to the bottom or top of the files and get only one cursor. :-) – Maxime Jul 21 '16 at 16:18
  • 4
    @sscarduzio or press *esc*. – ndnenkov Aug 24 '16 at 17:42
  • 4
    You can do this with fewer steps. After `Ctrl+Shift+L` just press `"`. Sublime is smart enough to put quotes on both sides of the selected text. – Martijn Heemels Mar 23 '17 at 10:34
  • @MartijnHeemels If you have empty lines, your method won't work. Sublime is smart... but not enough! ;-) – Maxime Mar 23 '17 at 17:17
  • @MartijnHeemels that doesn't work with _US - International_ layout. The _US_ layout is fine (I guess you use that one, can you confirm that?). I use _US - International_ so that I can make a _ü_ or _é_ easily. – Matt Nov 15 '17 at 08:54
  • @Matt It does work, but you'll need to type a after the double-quote. After all, the computer is waiting to see what comes after the double-quote to determine if you meant to type an accented character. Typing tells it you want the double-quote by itself. I use US International too, though I usually switch to US while programming. – Martijn Heemels Nov 15 '17 at 12:35
  • @MartijnHeemels I know, but then i end up with empty quotes/apostrophes, so it doesn't wrap the selection. Switch is indeed an option, and not to hard either. – Matt Nov 15 '17 at 12:39
  • @Matt That's strange. I just tested it before posting my comment and in my case it does. – Martijn Heemels Nov 16 '17 at 08:43
29

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, "

ndnenkov
  • 35,425
  • 9
  • 72
  • 104
  • Good answer. You can also find `^|$` and replace for `"` . This way you don't use capturing groups in find nor $1 in replace, but I really don't know about the performance of this. – sergioFC Aug 20 '15 at 21:07
  • @sergioFC, this won't work for the empty lines though. It will insert only one `"` as there is only one position to match at. But you do have a point that in the cases it does work, it is faster than matching the entire line. – ndnenkov Aug 20 '15 at 21:12
  • You are right it won't work if there are empty lines. Good point. – sergioFC Aug 20 '15 at 21:16
  • @ndn: I didn't get your first method. When I search for (.*), I get 'Unable to find (.*)' . May be I'm missing something. – Aniket Suryavanshi Aug 21 '15 at 05:55
  • @AniketSuryavanshi, you should enable regex search first if you haven't. For most people it's on by default. You can do that by checking the `.*` icon left of the search bar or by pressing `Alt+r` when your search is opened. – ndnenkov Aug 21 '15 at 05:58
  • For me, method 2 is deleting everything and I'm left with only one quote. – Maxime Aug 31 '15 at 12:31
4

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"
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
gdwitt
  • 111
  • 3