How to paste text to end of every line? Sublime 2

LineSublimetext2Text EditorCopy PasteSublimetext

Line Problem Overview


I'm curious if there is a way to paste text to the end of every line in Sublime 2? And conversely, to the beginning of every line.

test line one

test line two

test line three

test line four

...

Say you have 100 lines of text in the editor, and you want to paste quotation marks to the beginning and end of each line.

Is there an easy way to do this or a plugin that anyone would know of? This would often save me a lot of time on various projects.

Thanks.

Line Solutions


Solution 1 - Line

Yeah Regex is cool, but there are other alternative.

  • Select all the lines you want to prefix or suffix
  • Goto menu Selection -> Split into Lines (Cmd/Ctrl + Shift + L)

This allows you to edit multiple lines at once. Now you can add **Quotes (") or anything ** at start and end of each lines.

Solution 2 - Line

Here's the workflow I use all the time, using the keyboard only

  1. Ctrl/Cmd + A Select All
  2. Ctrl/Cmd + Shift + L Split into Lines
  3. ' Surround every line with quotes

Note that this doesn't work if there are blank lines in the selection.

Solution 3 - Line

  1. Select all the lines on which you want to add prefix or suffix. (But if you want to add prefix or suffix to only specific lines, you can use ctrl+Left mouse button to create multiple cursors.)
  2. Push Ctrl+Shift+L.
  3. Push Home key and add prefix.
  4. Push End key and add suffix.

>Note, disable wordwrap, otherwise it will not work properly if your lines are longer than sublime's width.

Solution 4 - Line

Let's say you have these lines of code:

test line one
test line two
test line three
test line four

Using Search and Replace Ctrl+H with Regex let's find this: ^ and replace it with ", we'll have this:

"test line one
"test line two
"test line three
"test line four

Now let's search this: $ and replace it with ", now we'll have this:

"test line one"
"test line two"
"test line three"
"test line four"

Solution 5 - Line

You can use the Search & Replace feature with this regex ^([\w\d\_\.\s\-]*)$ to find text and the replaced text is "$1".

Solution 6 - Line

Use column selection. Column selection is one of the unique features of Sublime2; it is used to give you multiple matched cursors (tutorial here). To get multiple cursors, do one of the following:

Mouse:

  • Hold down the shift (Windows/Linux) or option key (Mac) while selecting a region with the mouse.

  • Clicking middle mouse button (or scroll) will select as a column also.

Keyboard:

  • Select the desired region.
  • Type control+shift+L (Windows/Linux) or command+shift+L (Mac)

You now have multiple lines selected, so you could type a quotation mark at the beginning and end of each line. It would be better to take advantage of Sublime's capabilities, and just type ". When you do this, Sublime automatically quotes the selected text.

Type esc to exit multiple cursor mode.

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
QuestionTony H.View Question on Stackoverflow
Solution 1 - LinepalanirajaView Answer on Stackoverflow
Solution 2 - LinePatrick McDonaldView Answer on Stackoverflow
Solution 3 - LineHarryView Answer on Stackoverflow
Solution 4 - LineTomatroxView Answer on Stackoverflow
Solution 5 - LineYohannView Answer on Stackoverflow
Solution 6 - LinedbnView Answer on Stackoverflow