What Are These Numbers in Goto Anything of Sublime Text 2

What are these numbers in Goto Anything of Sublime Text 2

According to hearsay:

  • Indicator of how likely your input is meant to describe that file.
  • Increases with match quality. Typing in "application" in your screenshot should yield significantly higher numbers.
  • Increases with the popularity of the file. As a result, it will display the busiest file first if there are multiple matches.

Sublime Text go to character number

Open Goto Anything or Goto Line (accessible from the Goto menu, if you are not using keyboard shortcuts).

Type ::N where N is the Nth character in the file that you want to go to.
i.e. precede the number with 2 colons.

(Goto Line will prefill one :, so you only have to type one more. Alternatively, you could create a keybinding to execute command show_overlay with the following args, to prefill 2 colons: {"overlay": "goto", "text": "::"})


Alternatively, use the Find panel to search for the following regex:

\A[\s\S]{N-1}\K

replacing N-1 with the desired character number minus 1.

  • \A anchor from the beginning of the file
  • [\s\S] any whitespace or non-whitespace character
  • {N} match the previous character class N times i.e. {99} times so you end up with the caret immediately to the left of the 100th character
  • \K clear what has matched so far

Sublime Text - Goto line and column

Update 3

This is now part of Sublime Text 3 starting in build number 3080:

Goto Anything supports :line:col syntax in addition to :line

For example, you can use :30:11 to go to line 30, column 11.

Update 1 - outdated

I just realized you've tagged this as sublime-text-3 and I'm using 2. It may work for you, but I haven't tested in 3.

Update 2 - outdated

  • Added some sanity checks and some modifications to GotoRowCol.py
  • Created github repo sublimetext2-GotoRowCol
  • Forked and submitted a pull request to commit addition to package_control_channel

Edit 3: all requirements of the package_control repo have been met. this package is now available in the package repository in the application ( install -> GotoRowCol to install ).

I too would like this feature. There's probably a better way to distribute this but I haven't really invested a lot of time into it. I read through some plugin dev tutorial really quick, and used some other plugin code to patch this thing together.

Select the menu option Tools -> New Plugin

A new example template will open up. Paste this into the template:

import sublime, sublime_plugin

class PromptGotoRowColCommand(sublime_plugin.WindowCommand):
def run(self, automatic = True):
self.window.show_input_panel(
'Enter a row and a column',
'1 1',
self.gotoRowCol,
None,
None
)
pass

def gotoRowCol(self, text):
try:
(row, col) = map(str, text.split(" "))

if self.window.active_view():
self.window.active_view().run_command(
"goto_row_col",
{"row": row, "col": col}
)
except ValueError:
pass

class GotoRowColCommand(sublime_plugin.TextCommand):
def run(self, edit, row, col):
print("INFO: Input: " + str({"row": row, "col": col}))
# rows and columns are zero based, so subtract 1
# convert text to int
(row, col) = (int(row) - 1, int(col) - 1)
if row > -1 and col > -1:
# col may be greater than the row length
col = min(col, len(self.view.substr(self.view.full_line(self.view.text_point(row, 0))))-1)
print("INFO: Calculated: " + str({"row": row, "col": col})) # r1.01 (->)
self.view.sel().clear()
self.view.sel().add(sublime.Region(self.view.text_point(row, col)))
self.view.show(self.view.text_point(row, col))
else:
print("ERROR: row or col are less than zero") # r1.01 (->)

Save the file. When the "Save As" dialog opens, it should be in the the Sublime Text 2\Packages\User\ directory. Navigate up one level to and create the folder Sublime Text 2\Packages\GotoRowCol\ and save the file with the name GotoRowCol.py.

Create a new file in the same directory Sublime Text 2\Packages\GotoRowCol\GotoRowCol.sublime-commands and open GotoRowCol.sublime-commands in sublime text. Paste this into the file:

[
{
"caption": "GotoRowCol",
"command": "prompt_goto_row_col"
}
]

Save the file. This should register the GotoRowCol plugin in the sublime text system. To use it, hit ctrl + shift + p then type GotoRowCol and hit ENTER. A prompt will show up at the bottom of the sublime text window with two number prepopulated, the first one is the row you want to go to, the second one is the column. Enter the values you desire, then hit ENTER.

I know this is a complex operation, but it's what I have right now and is working for me.

Sublime Text Fuzzy file Search numbers

Seem like it has been answered in other related SO thread:

  • Indicator of how likely your input is meant to describe that file.
  • Increases with match quality. Typing in "application" in your screenshot should yield significantly higher numbers.
  • Increases with the popularity of the file. As a result, it will display the busiest file first if there are multiple matches.

Remember search query in Sublime Text 3

You can use a plugin that saves the content of the gotoAnything-panel when its modified, and then puts the content on the panel when it gets opened.

Basic plugin example:

import sublime, sublime_plugin

class GotoAnythingSaver(sublime_plugin.EventListener): # Use EventListener
# In my case gotoAnything view id is 2.

def on_modified(self, view): # This is called when a view is modified (text changed)
if (view.id() == 2): # Save content
self.content = self.get_view_content(view)

def on_activated_async(self, view): # This is called when a view is activated
if view.id() == 2 and hasattr(self, 'content'): # Restore content if empty
if not self.get_view_content(view):
view.run_command('insert', {"characters":self.content})

def get_view_content(self, view):
return view.substr(sublime.Region(0, view.size()))

To save the plugin use menu Tools>new Plugin and then save it in the given folder (folder name should be User), use fileName GotoAnythingSaver.py.


Example result used to go to the same line again:

Sublime goto anything saver, a plugin that restores goto-anythin content


Edit: tested on Sublime Text 3 build 3103 on Linux Mint and Windows 10. OP says this plugin leave the gotoanything dysfunctional, this doesn't happened to me, but be careful.

I would appreciate if someone could test it or help me, because I am not sure if the identifier of the view associated with goto-anything panel is always 2.

Sublime Text 2 console input

Sublime text doesn't support that. But you can get around it (at least in python) by using SublimeREPL, I use this for everything, it works pretty great. Its a little cooky though, as the tab is still editable like a normal sublime tab (which is good and bad)...

It also allows you to run the interpreter in multiple tabs, its basically awesome.

To install it you need package control this lets you easily install plugins. To get it go here, and follow the instructions. Once thats done:

  • in Sublime press ctrl + shift + P (linux command in ST for 'goto anything').
  • Type in 'install',
  • click on 'sublime package control: install package'.
  • Then select SublimeREPL. It will install it automatically.
  • To use it go to Tools>sublimerepl>python from the menus.

To make the default build system SublimeREPL, you can follow these instructions.

Moving the cursor/point in a Sublime Text 2 Plugin

In the default plugins folder there is a plugin called goto_line.py that does pretty much exactly this.

import sublime, sublime_plugin

class PromptGotoLineCommand(sublime_plugin.WindowCommand):

def run(self):
self.window.show_input_panel("Goto Line:", "", self.on_done, None, None)
pass

def on_done(self, text):
try:
line = int(text)
if self.window.active_view():
self.window.active_view().run_command("goto_line", {"line": line} )
except ValueError:
pass

class GotoLineCommand(sublime_plugin.TextCommand):

def run(self, edit, line):
# Convert from 1 based to a 0 based line number
line = int(line) - 1

# Negative line numbers count from the end of the buffer
if line < 0:
lines, _ = self.view.rowcol(self.view.size())
line = lines + line + 1

pt = self.view.text_point(line, 0)

self.view.sel().clear()
self.view.sel().add(sublime.Region(pt))

self.view.show(pt)


Related Topics



Leave a reply



Submit