Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

First class Sublime Text AI assistant with gpt-5, o3 and ollama support!

License

NotificationsYou must be signed in to change notification settings

yaroslavyaroslav/OpenAI-sublime-text

Repository files navigation

Star on GitHubPackage Control

OpenAI Sublime Text Plugin

tldr;

Cursor level of AI assistance for Sublime Text. I mean it.

Works with all OpenAI'ish API:llama.cpp server,ollama or whatever third party LLM hosting. Claude API support coming soon.

Note

This plugin is in its pretty much finite state as it is, with persistent dialog storage and Phantoms support. So

  • No more connector will added here (Antropic, Gemini, etc)
  • No more tools support will be added also.
  • Same as no MCP server support will be provided as well.1

The good news is that all of those available out of the box in my nextCodexSublime plugin which leverages all these thing onopenai/codex obviously. Check it out.

Features

  • Chat mode powered by whatever model you'd like.
  • gpt-5 support.
  • llama.cpp's server,ollama and all the rest OpenAI'ish API compatible.
  • Dedicated chats histories and assistant settings for a projects.
  • Ability to send whole files or their parts as a context expanding.
  • Phantoms Get non-disruptive inline right in view answers from the model.
  • Markdown syntax with code languages syntax highlight (Chat mode only).
  • Server Side Streaming (SSE) streaming support.
  • Status bar various info: model name, mode, sent/received tokens.
  • Proxy support.

Requirements

  • Sublime Text 4
  • llama.cpp,ollama installedOR
  • Remote llm service provider API key, e.g.OpenAI
  • Anthropic API key [coming soon].

Installation

Via Package Control

  1. Install the Sublime TextPackage Control plugin if you haven't done this before.
  2. Open the command palette and typePackage Control: Install Package.
  3. TypeOpenAI and pressEnter.

Via Git Clone

  1. Go to your packages folder:Preferences: Browse Packages.
  2. Rungit clone https://github.com/yaroslavyaroslav/OpenAI-sublime-text.git OpenAI\ completion in that folder that Sublime opened.
  3. Open Sublime Text and let it installed the dependencies.
  4. It may ask you to restart Sublime, do that if it does.
  5. Open Sublime again and typeOpenAI and pressEnter.

Usage

Interacting with the AI

You can interact with the AI in several ways, primarily through commands available in the Sublime Text Command Palette:

  1. Select Text (Optional): You can select a region of text in your current file to be included as part of the context for your prompt.
  2. Choose Your Command:
    • OpenAI: Chat Model Select: This is the most flexible command. It opens a panel allowing you to:
      • Choose a specific "assistant" (which defines the model, API key, temperature, etc.).
      • Select an "output_mode" (inlinePhantom or a chatView in a panel/new tab).This command automatically includes any files you've marked for context (see "Additional Request Context Management" below).
    • OpenAI: New Message: This command sends your input directly using the assistant and output mode that were last selected or are currently active. It's quicker if you're consistently using the same settings. This command also includes any files marked for context.
  3. Input Your Prompt: An input panel will appear, allowing you to type your question or instruction for the AI.
  4. View Response:
    • The AI's response will typically appear in the OpenAI output panel.
    • If you chose "Phantom" mode (withOpenAI: Chat Model Select), the response will appear as an inline overlay.
    • You can switch to a dedicated tab for the chat using theOpenAI: Open in Tab command.

Including Build/LSP Output:For more specific contexts, especially when coding, you can use commands that automatically include output from Sublime Text's diagnostic panels:

  • OpenAI: New Message With Build Output
  • OpenAI: Chat Model Select With Build Output
  • OpenAI: New Message With LSP Output
  • OpenAI: Chat Model Select With LSP Output

These commands will append recent lines from the respective output panels (Build results or LSP diagnostics) to your request. The number of lines included can be configured with thebuild_output_limit setting inopenAI.sublime-settings. This is useful for asking the AI to explain errors, debug code, or summarize diagnostics.

Managing Chat Sessions:

  • OpenAI: Refresh Chat: Reloads the chat history into the output panel or tab.
  • OpenAI: Reset Chat History: Clears the chat history for the current context (project-specific or global).

Chat history management

You can separate a chat history and assistant settings for a given project by appending the following snippet to its settings:

{"settings": {"ai_assistant": {"cache_prefix":"/absolute/path/to/project/"        }    }}

Additional Request Context Management

You can include the content of specific files as context for the AI. Files marked for context will have their content sent along with your prompt. There are several ways to manage this:

  • Using the Command Palette:
    • Run theOpenAI: Add Sheets to Context command. If you run this while one or more tabs are selected (e.g., usingCtrl+Click orCmd+Click on tabs, or by selecting files in the sidebar that get focused as tabs), it will toggle their inclusion in the AI context.
  • Using the Tab Context Menu:
    • Right-click on an open tab and selectOpenAI: Add File to Context from the context menu to toggle its inclusion.
  • Using the Sidebar Context Menu:
    • Right-click on a file or a selection of files in the sidebar and chooseOpenAI: Add File to Context from the context menu to toggle their inclusion.

Once files are added to the context:

  • You can see the number of currently included sheets in the status bar (if this option is enabled in thestatus_hint setting).
  • TheOpenAI: Chat Model Select command preview panel will also list the files currently included.
  • To view all files currently marked for context in the current window, run theOpenAI: Show All Selected Sheets command from the Command Palette. This will select these files in their respective views/groups.

Files can be deselected using the same methods (the commands effectively toggle the inclusion status).

Image handling

Image handle can be called byOpenAI: Handle Image command.

It expects an absolute path to image to be selected in a buffer or stored in clipboard on the command call (smth like/Users/username/Documents/Project/image.png). In addition command can be passed by input panel to proceed the image with special treatment.png andjpg images are only supported.

Note

Currently plugin expects the link or the list of links separated by a new line to be selected in buffer or stored in clipboardonly.

In-buffer llm use case

Phantom use case

Phantom is the overlay UI placed inline in the editor view (see the picture below). It doesn't affects content of the view.

  1. [optional] Select some text to pass in context in to manipulate with.
  2. PickPhantom as an output mode in quick panelOpenAI: Chat Model Select.
  3. After the AI responds, the phantom will display actions like:
    • [x] (Close): Dismisses the phantom.
    • Copy: Copies the AI's response (or just the code, ifphantom_integrate_code_only is true) to the clipboard.
    • Append: Appends the AI's response to the end of your current selection in the editor (or at the cursor position if no selection).
    • Replace: Replaces your current selection with the AI's response.
    • In New Tab: Opens the AI's full response in a new tab.
    • Add to History: Saves the current interaction (your prompt and the AI's response) to the chat history panel/view.
  4. You can hitctrl+c to stop prompting same as with inpanel mode.

Other features

Open Source models support (llama.cpp, ollama)

  1. Replace"url" setting of a given model to point to whatever host you're server running on (e.g.http://localhost:8080/v1/chat/completions).
  2. Provide a"token" if your provider required one.
  3. Tweak"chat_model" to a model of your choice and you're set.

Google Gemini models

  1. Replace"url" setting of a given model to point to theGoogle Gemini OpenAI compatible API:https://generativelanguage.googleapis.com/v1beta/openai/chat/completions.
  2. Provide a"token" if your provider required one.
  3. Tweak"chat_model" toa model from the list of supported models.

You can read moreabout OpenAI compatibility in the Gemini documentation.

Note

You can set bothurl andtoken either global or on per assistant instance basis, thus being capable to freely switching between closed source and open sourced models within a single session.

Settings

The OpenAI Completion plugin has a settings file where youcan set your OpenAI API key. This is required for the most of providers to work. To set your API key, open the settings with thePreferences: OpenAI Settings command and paste your API key in the token property, as follows: You can also access these settings and the default keybindings via the main menu:Preferences -> Package Settings -> OpenAI completion.

{"token":"sk-your-token",}

Advertisement disabling

To disable advertisement you have to add"advertisement": false line into an assistant setting where you wish it to be disabled.

Key Bindings

You can create custom keybindings for OpenAI commands by adding entries to your user keymap file. Access this file via the Command Palette (Preferences: Key Bindings) or the main menu (Preferences -> Key Bindings). Sublime Text keybindings often use sequences, for example, pressingsuper+k (orctrl+k on Windows/Linux) followed by another key.

Here are some examples to get you started:

1. New Message with current assistant (includes files marked for context):

{"keys": ["super+k","m"],// macOS: Cmd+k, then m"command":"openai"}

2. Open Chat Model Select panel (includes files marked for context):

{"keys": ["super+k","super+m"],// macOS: Cmd+k, then Cmd+m"command":"openai_panel"}

3. New Message with Build Output (using current assistant):

{"keys": ["super+k","b"],// macOS: Cmd+k, then b"command":"openai","args": {"build_output":true }}

4. Toggle current file's inclusion in AI Context (matches "OpenAI: Add Sheets to Context" command):

{"keys": ["super+k","c"],// macOS: Cmd+k, then c"command":"toggle_view_ai_context_included"}

5. Show the AI Chat output panel:

{"keys": ["super+k","p"],// macOS: Cmd+k, then p"command":"show_panel","args": {"panel":"output.AI Chat" }}

Proxy support

You can setup it up by overriding the proxy property in theOpenAI completion settings like follow:

"proxy":{"address":"127.0.0.1",// required"port":9898,// required"username":"account","password":"sOmEpAsSwOrD"}

Disclaimers

Warning

All selected code will be sent to the OpenAI servers (if not using custom API provider) for processing, so make sure you have all necessary permissions to do so.

Note

Dedicated to GPT3.5 that one the one who initially written at 80% of this back then. This was felt like a pure magic!

Footnotes

  1. PR's are welcome tho.

About

First class Sublime Text AI assistant with gpt-5, o3 and ollama support!

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors14

Languages


[8]ページ先頭

©2009-2026 Movatter.jp