Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sublime text select first in each line

Tags:

In Vim there's a really nice feature to find/replace the first occurrence in each line. This is afaik actually the default behavior. How can I obtain the same behavior in sublime text?

I need to be able to mark/find the FIRST (and the first only!) character, e.g. '=', in each line, so that I easily can mark/copy/cut what's before and what's after that specific character. Mind you, there might be many of this specific character in each line.

Concrete example:

I have a long list of java properties in the form:

my.property.link1=<a href="asdfs">Link 1</a>
my.property.link22=<a href="asdfs">Link 22</a>
my.property.link333=<a href="asdfs">Link 333</a>
my.property.link4444=<a href="asdfs">Link 4444</a>

I want to mark the first "=" in each line, to be able to select all the preceding text (indifferent from the amount of text preceding the "=") to cut or copy the text. The paste-result of such action would be:

my.property.link1
my.property.link22
my.property.link333
my.property.link4444
like image 664
Hoof Avatar asked Apr 15 '13 14:04

Hoof


People also ask

How do you select multiple words in Sublime Text?

Splitting the Selection into Lines Select a block of lines, and then split it into many selections, one per line, using: Windows/Linux: Ctrl+Shift+L. Mac: ⇧+⌘+L.

How do I use multiple cursors in Sublime Text 3?

While you can place multiple text cursors in Sublime Text with Cmd–Click (Mac) or Ctrl–Click (Windows), here's another technique that comes in handy. Hold Ctrl–Shift (Mac) or Ctrl–Alt (Windows) and hit Up or Down Arrow to place an additional text cursor above or below the current cursor.


2 Answers

I actually wrote a sublime plugin called SelectUntil that addresses this exact problem: https://github.com/xavi-/sublime-selectuntil

Once it's install you can do the following

  • Select all the line you'd like edit or partially copy
  • Press Cmd/Ctrl + Shift + L -- this gives each line it's own cursor.
  • Bring each cursor to the beginning of it's line by pressing Home or Ctrl + A if you're using OSX
  • Press Ctrl/Alt + Shift + S to activate SelectUntil
  • Tell SelectUntil to select until the equals sign by typing = + Enter
  • Hit shift + to deselect the equals sign
  • At this point the names of all the properties should be selected so you can copy/paste as you'd like

The experience should look something like this:

enter image description here

like image 107
Xavi Avatar answered Oct 05 '22 03:10

Xavi


Supposing you have the following text:

my.property.link1=<a href="asdfs">Link 1</a>
my.property.link22=<a href="asdfs">Link 22</a>
my.property.link333=<a href="asdfs">Link 333</a>
my.property.link4444=<a href="asdfs">Link 4444</a>

Press Ctrl + F (or click Find->Find)

Enable regular expressions

Type in the search field: ^.*?(?==)

Preess Alt + Enter (or click Find All)

Now all the text before = is selected, you just need to copy it.

like image 24
Hugo Corrá Avatar answered Oct 05 '22 04:10

Hugo Corrá