Sublime Forum

Search for text in a specific position

#1

Hi,
The ISPF editor on the IBM Mainframe lets me search for a text string starting in a particular position (column) in the file. So if I am working with a text file that has say a 100 bytes on each line, I can search for the string only starting from the 50th byte.
Is this possible in Sublime Text?
Thanks!

0 Likes

#2

Is possible, with the following code, you may start a plugin to get the utility. View -> Show Console :

[view.sel().add(sublime.Region(line.a+10, line.b)) for line in view.lines(sublime.Region(0,view.size())) if line.size() > 10]

This will search for each line that has more than 10 characters (please note this searches for characters not bytes), and create a selection from 10 to the end of the line… then you may use: Main menu bar -> Find -> … and in the tiny toolbar at bottom, check “in selection”. Then ST will in theory search in the selections. You may can get something similar using regular expressions, such:

[view.sel().add(search) for search in view.find_all(’[^\n]{10,}(my search)^\n]*\n’, sublime.IGNORECASE)]

or just selecting one by one, with something like

current_sel=view.sel()[0]; view.sel().clear(); region =view.find(’^\n]{10,}(my search)^\n]*\n’, current_sel.b, sublime.IGNORECASE); view.sel().add(region); view.show_at_center(region);

just an introduction

0 Likes

#3

Hi,

Depending on your needs, it may be easier to use regular expressions (look behinds). For example:

(?<=^.{50}).*foo

will find lines containing the “foo” sequence after column 50.

It’s not a real LOCATE command but it’s often enough.

Hope this helps.

Martin
(my kingdom for a real ALL command; that’s all I miss in ST and there is no real way to emulate it, alas.)

0 Likes

#4

[quote=“tito”]Is possible, with the following code, you may start a plugin to get the utility. View -> Show Console :

[view.sel().add(sublime.Region(line.a+10, line.b)) for line in view.lines(sublime.Region(0,view.size())) if line.size() > 10]

This will search for each line that has more than 10 characters (please note this searches for characters not bytes), and create a selection from 10 to the end of the line… then you may use: Main menu bar -> Find -> … and in the tiny toolbar at bottom, check “in selection”. Then ST will in theory search in the selections. You may can get something similar using regular expressions, such:

[view.sel().add(search) for search in view.find_all(’[^\n]{10,}(my search)^\n]*\n’, sublime.IGNORECASE)]

or just selecting one by one, with something like

current_sel=view.sel()[0]; view.sel().clear(); region =view.find(’^\n]{10,}(my search)^\n]*\n’, current_sel.b, sublime.IGNORECASE); view.sel().add(region); view.show_at_center(region);

just an introduction[/quote]

Thanks Tito. Many options! I have some production problems to fix right now so it might be a bit before I can try to experiment with this.

0 Likes