Command Prompt/Terminal in Sublime Text in split-view

Learn how to add a command prompt or terminal in sublime text with split-view at the bottom of the current editor tab.

Sublime text is an exceptional text and code editing tool. It’s fast, powerful and extensible with many packages. However, it doesn’t have an inbuilt terminal to execute code. To use a terminal, one must download third party package from the package manager. Even with this package, terminal opens in a new tab. For the terminal to open on the same window with a split view, you need yet another package. However, they are light and don’t take a lot of space, so let’s get started.

Sublime Text 3 with Command Prompt on split view
Sublime Text 3 with Command Prompt on split view

If you know how to handle packages and key-bindings, the packages you need are Terminus and Origami. You can add them to Sublime Text and start using Terminal. Origami’s split view feature makes split view pane work with Terminus.

the package control view with install package option shown
Open the package control (Ctrl+Shift+p) and install a new package

Terminus

Terminus is the first package you need to install on your sublime text. This is a powerful terminal with a build system and can also display images. It works on all platforms so you can have a consistent terminal for your code editor. It is also compatile with all operating system.

Terminus package from the repository
Terminus package from the repository

To add terminus to sublime text,

  • Open the quick access panel (Ctrl+Shift+P)(Cmd+Shift+P on Mac)
  • Search for “Install Package”
  • Wait for the repository to update and display the list of packages
  • Search for “Terminus”
  • Once found, select and press Enter

You can now use the terminal from your quick access panel by searching “terminus”. You’re taken to the new tab with the terminal. This isn’t exactly user friendly, and it doesn’t initialize relative to the current directory. A new package called Origami fixes this. It allows you to split view different window panes however you like them (left, right, top, and bottom).

Origami

Install Origami with steps similar to Terminus above. Now we’ll create a key-binding to open a terminal window pane below the current tab with the current directory as the working directory. If you already have key-bindings, incorporate the following code.

To edit key-bindings in Sublime Text 3:

  • Go to Preferences Menu
  • Select Key Bindings
[
    { 
        "keys": ["alt+`"], 
            "command": "terminus_open", 
            "args": {
                "cwd": "${file_path:${folder}}",
                "post_window_hooks": [
                    ["carry_file_to_pane", {"direction": "down"}]
                ]
        }
    },
    { 
        "keys": ["ctrl+w"], 
            "command": "terminus_close", 
            "context": [{ "key": "terminus_view"}]
        }
]

Above codes sets “Alt+`” to open a Origami pane at the bottom of the current tab in split-view. Second key-binding “Ctrl+w” is to close the terminal. You will have to close the split-view pane manually by left clicking inside the pane, then go to “Origami”, and “Close current”. To close the pane as well, you will need to chain multiple commands which is only possible if you add another package called “Chain of Command”.

Leave a Reply