Create a plugin that allows you to search Sublime Text 3 tabs in Python

I open a lot of tabs in Sublime Text3. How are you looking for the target tab in a lot of tabs? I think there are various ways to do it, but I think most of them will be as follows.

--Search by moving with ctrl + tab (control + tab) --Jump by number with Alt + number (Command + number) --Do not open a lot of tabs in the first place. .. ..

Of these, it's annoying to search with ctrl + tab, and jumping with ʻAlt + number` has more than 10 tabs open, and I don't know the number in the first place. .. .. The third is a little. .. ..

So, I made a function to search tabs after studying. By the way, I'm new to Python.

Does Sublime have a tab search function in the first place?

Premise

--Windows --Sublime Text 3 is translated into Japanese

Preparing to create a plugin

Click [Tools] => [Add Plugin]. A template will be created, so save it with ctrl + s.

Make sure Packages / User is selected as the save location, and save a suitable name with the extension .py.

Write source code

Tab search can be realized only with the following source code. Very easy

import sublime, sublime_plugin
import os

class FindTabListCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        def on_done(index):
            if index == -1:
                return;
            window = sublime.active_window()
            tabs = window.views_in_group(window.active_group())
            window.focus_view(tabs[index])
        
        window = sublime.active_window()
        tabs = window.views_in_group(window.active_group())
        tabNames = []
        for item in tabs:
            if item.name() != "Find Results":
                fileName = os.path.basename(item.file_name())
                tabNames.append(fileName)

        window.show_quick_panel(tabNames, on_done)

Set a shortcut

Set the key binding settings as follows and you're done.

{ "keys": ["ctrl+t"], "command": "find_tab_list"}

When executed, Sublime will open the familiar search box below and you can search for tabs.

2016-12-20_20h47_23.png

Recommended Posts

Create a plugin that allows you to search Sublime Text 3 tabs in Python
Create a plugin that always highlights arbitrary text in Sublime Text 2
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
Created a service that allows you to search J League data
A memo that allows you to change Pineapple's Python environment with pyenv
I want to create a window in Python
How to create a JSON file in Python
Create a python3 build environment with Sublime Text3
I tried to create a class that can easily serialize Json in Python
I want to create a priority queue that can be updated in Python (2.7)
What to do if a Unicode Encode Error occurs in Sublime Text Python
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create a Wox plugin (Python)
Create a function in Python
Create a dictionary in Python
Speech to speech in python [text to speech]
Introducing the book "Creating a profitable AI with Python" that allows you to learn machine learning in the shortest course
I tried to make it on / off by setting "Create a plug-in that highlights double-byte space with Sublime Text 2".
Let's create a script that registers with Ideone.com in Python.
How to import a file anywhere you like in Python
Create code that outputs "A and pretending B" in python
Create a tool to check scraping rules (robots.txt) in Python
A learning roadmap that allows you to develop and publish services from scratch with Python
Introducing "Sherlock", a CLI tool that allows you to search for user names across SNS
A Python script that allows you to check the status of the server from your browser
Write a binary search in Python
GOTO in Python with Sublime Text 3
Create a DI Container in Python
Create a binary file in Python
Write a vim plugin in Python
Write a depth-first search in Python
Create a Kubernetes Operator in Python
5 Ways to Create a Python Chatbot
Create a random string in Python
What to do if you get a minus zero in Python
[Python / Django] Create a web API that responds in JSON format
How to create a heatmap with an arbitrary domain in Python
I want to do a full text search with elasticsearch + python
If you want to assign csv export to a variable in python
Let's create a Python directory structure that you won't regret later
Check if you can connect to a TCP port in Python
We have released an extension that allows you to define xarray data like a Python data class.
Create a shortcut to run a Python file in VScode on your terminal
I made a web application in Python that converts Markdown to HTML
What to do if you can't use scikit grid search in Python
Note: [Python3] Convert datetime to a string in any format you like
Create a simple GUI app in Python
Create a JSON object mapper in Python
Introduction of "scikit-mobility", a library that allows you to easily analyze human flow data with Python (Part 1)
[Python / Tkinter] Search for Pandas DataFrame → Create a simple search form to display
How to get a stacktrace in python
I tried to develop a Formatter that outputs Python logs in JSON
[Python] Create a LineBot that runs regularly
[GPS] Create a kml file in Python
Write a simple Vim Plugin in Python 3
Let's create a customer database that automatically issues a QR code in Python
[Python] [Word] [python-docx] Try to create a template of a word sentence in Python using python-docx
I wrote a book that allows you to learn machine learning implementations and algorithms in a well-balanced manner.
What is the fastest way to create a reverse dictionary in python?
[Python3] Code that can be used when you want to cut out an image in a specific size