Reputation: 1758
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
Upvotes: 21
Views: 42947
Reputation: 81
[CTRL + A] ; [CTRL + Shift + L] ; [Home]
make a AutoItInputMacro.exe Map that to [Home] 1 press button GG No rematch.
Upvotes: 8
Reputation: 49
For this problem, you can use the command line cc.gbc 1/=/
of ConyEdit (a plugin) to get the text before the first column of regex match.
Upvotes: 0
Reputation: 486
Select all with Ctrl + A
then press Ctrl + Shift + L
and finally go to "Selection-> Invert Selection" like the picture et Voila!:
Upvotes: 0
Reputation: 20439
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
The experience should look something like this:
Upvotes: 40
Reputation: 14799
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.
Upvotes: 26
Reputation: 1427
Tried this and it seems to work:
Regex find using ^(.*)(STRING_TO_MATCH)
\1 will give all the stuff before your match, \2 gives the match itself.
You could also use ^(.*)(STRING_TO_MATCH)(.*) and then \3 would be everything after.
Edit - if you're looking to select and copy, I tried this: ^[^CHAR]*
This will find everything from the beginning of the line up to and not including your character. From there you can right click to copy. I haven't found a keystroke sequence to do it since the find panel has focus, maybe you can figure it out.
Upvotes: 3
Reputation: 14799
Supposing you have the following text:
AAAABBBCCCC
ABC
BBBAAACCC
ABCABCABC
..and you want to replace every first occurrence of A in each line by X:
Press Ctrl + H (or click Find->Replace)
Find what: A(.*)
Replace With: X\1
Then click in replace all.
Upvotes: 2