How to wrap each line in quotes in SublimeText?
36,864
Solution 1
I would use a multiple cursors approach like this:
Windows
- Ctrl + A (Select everything)
- Ctrl + Shift + L (Split into lines)
- End (Put the cursor at the end of the line)
- " (Add the quote at the end of the line)
- Home (Go to the first character of the line)
- Home (Go to the beginning of the line... like if you have tabs or spaces)
- " (Add the quote at the beginning of the line)
Mac
- Cmd + A (Select everything)
- Cmd + Shift + L (Split into lines)
- Cmd + → (Put the cursor at the end of the line)
- " (Add the quote at the end of the line)
- Cmd + ← (Go to the first character of the line)
- Cmd + ← (Go to the beginning of the line... like if you have tabs or spaces)
- " (Add the quote at the beginning of the line)
Solution 2
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
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"
Comments
-
Aniket Suryavanshi over 3 years
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?
-
sergioFC almost 9 yearsGood 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. -
ndnenkov almost 9 years@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. -
sergioFC almost 9 yearsYou are right it won't work if there are empty lines. Good point.
-
Aniket Suryavanshi almost 9 years@ndn: I didn't get your first method. When I search for (.*), I get 'Unable to find (.*)' . May be I'm missing something.
-
ndnenkov almost 9 years@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 pressingAlt+r
when your search is opened. -
Maxime almost 9 yearsFor me, method 2 is deleting everything and I'm left with only one quote.
-
sscarduzio almost 8 yearscool, but: how in the name of god I exit this multi cursor mode now??
-
Maxime almost 8 yearsSimply click somewhere else. Or use the arrows to go to the bottom or top of the files and get only one cursor. :-)
-
ndnenkov almost 8 years@sscarduzio or press esc.
-
Devplex over 7 yearsYou 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. -
Maxime over 7 years@MartijnHeemels If you have empty lines, your method won't work. Sublime is smart... but not enough! ;-)
-
Devplex over 7 years@Maxime Thanks, I didn't realize that.
-
Neeraj Gupta about 7 yearsWow. This answer has saved my day from regexing and substituting . thanks
-
Maximus almost 7 yearsYou are a god among men. Thanks for saving me a lot of time. But, now that I'm billing my clients hourly I'll need to find some other tasks to do!
-
Matt over 6 years@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.
-
Devplex over 6 years@Matt It does work, but you'll need to type a <space> 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 <space> tells it you want the double-quote by itself. I use US International too, though I usually switch to US while programming.
-
Matt over 6 years@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.
-
Devplex over 6 years@Matt That's strange. I just tested it before posting my comment and in my case it does.