• Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard
CSEstack

What do you want to Learn Today?

  • Programming
    • Tutorial- C/C++
    • Tutorial- Django
    • Tutorial- Git
    • Tutorial- HTML & CSS
    • Tutorial- Java
    • Tutorial- MySQL
    • Tutorial- Python
    • Competitive Coding Challenges
  • CSE Subject
    • (CD) Compiler Design
    • (CN) Computer Network
    • (COA) Computer Organization & Architecture
    • (DBMS) Database Management System
    • (DS) Data Structure
    • (OS) Operating System
    • (ToA) Theory of Automata
    • (WT) Web Technology
  • Interview Questions
    • Interview Questions- Company Wise
    • Interview Questions- Coding Round
    • Interview Questions- Python
    • Interview Questions- REST API
    • Interview Questions- Web Scraping
    • Interview Questions- HR Round
    • Aptitude Preparation Guide
  • GATE 2022
  • Linux
  • Trend
    • Full Stack Development
    • Artificial Intelligence (AI)
    • BigData
    • Cloud Computing
    • Machine Learning (ML)
  • Write for Us
    • Submit Article
    • Submit Source Code or Program
    • Share Your Interview Experience
  • Tools
    • IDE
    • CV Builder
    • Other Tools …
  • Jobs

How to Open Command Line Prompt From Sublime Editor in Windows?

Aniruddha Chaudhari/27597/12
Software Installation

In this article, I am sharing step by steps procedure open command line prompt from Sublime editor.

Before starting this tutorial, let me tell you, that Sublime is one of the best editors for programming. I personally use it.

Why should you use the Sublime editor, too?

It supports and highlights syntax for so many programming languages. If you dabble in many programming languages, it is not a good choice to keep one editor (IDE) specific for each programming language.

Using a single editor makes your job easy. So the sublime is the best choice for you.

If you are not using it and are serious about coding, I would recommend you to download and install Sublime. Get your own experience before I explain you further.

Now moving to our tutorial guide.

How to Open Command Line Prompt From Sublime Editor?

Sublime is just an editor that highlights coding syntax.

After writing any programming, you save it. Then, you have to compile and run it. Unfortunately, Sublime does not have the intelligence to compile and run you’re any program.

Whether if it is Python or C/C++ programming, you need to the compile and run it through the command prompt (cmd).

After writing a program, you can not open the command prompt from the Sublime editor.

What do you do?

“Minimize the Sublime editor and open command prompt from Windows application stray”.

then…

“Change the current directory of the command prompt where the program is saved. “

Two things bothered me much….

Opening command prompt explicitly. And the changing current directory of the command prompt for every program I run.

So, here I am giving the solution to my both problems by which you can open a command prompt from the Sublime editor with a single click.

Step by step procedure:

Follow the procedure…

  • Open Sublime editor.
  • Click on the Preferences and then select Browser Packages…
  • It will open a new window. Create a new folder CMD (all uppercase letters).
  • Create a file cmd.py. Write the below code and save the file.
import os, sublime_plugin
class CmdCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        file_name=self.view.file_name()
        path=file_name.split("\\")
        current_driver=path[0]
        path.pop()
        current_directory="\\".join(path)
        command= "cd "+current_directory+" & "+current_driver+" & start cmd"
        os.system(command)

This is Python coding. It is ok even if you don’t understand this code. This code is tested and verified.

  • Create another file with a name Context.sublime-menu. Copy and paste the lines given below into the file and save it.
[
     { "command": "cmd" }
]

That is all. Your job is done.

Verify:

Now, just test it.

  • Open any program file in the sublime editor and Right-click (context menu).
  • You can see the Cmd menu in the Context menu options.
  • Click on it.
  • The command prompt will be opened through which you can compile and run your program.

Tip: If you want to excel in programming, get rid of using the mouse. And try to get the things done from keyboard shortcuts in the jiffy.

Rather than Right-click every time to open a command prompt, I prefer to use the keyboard shortcut.

Keyboard shortcut to Open Command Prompt:

In the Sublime editor, click on Preferences and select Key Bindings – User.

If you want to open a command line prompt by command (by ‘cmd’ for example),  Add the following context data into the Default (Windows).sublime-keymap file. :

{ "keys": ["c", "m", "d"], "command": "cmd"}

I am habitat opening command prompt using commandcmd through W+Run. So I prefer using the same shortcode for Sublime. You can set any keyboard shortcuts you feel comfortable with.

It makes your programming faster. And who doesn’t like that?

Sublime is a generic IDE that supports many languages. If you are a Python programmer, you may like to use PyCharm IDE. It is built specifically for Python project development. Check out our complete PyCharm installation and configuration tutorial.

This is all from this tutorial to open command line prompt from Sublime. If you face any challenges in configuring the Sublime editor, write your query in the comment.

Happy Programming!

editorIDESublime
Aniruddha Chaudhari
I am complete Python Nut, love Linux and vim as an editor. I hold a Master of Computer Science from NIT Trichy. I dabble in C/C++, Java too. I keep sharing my coding knowledge and my own experience on CSEstack.org portal.

Your name can also be listed here. Got a tip? Submit it here to become an CSEstack author.

Comments

  • Reply
    Abram Coder
    November 12, 2017 at 8:15 am

    I did not think of this earlier. I was used to open command prompt explicitly every time running program. Thanks for these tips. It is really time-saving for me.

    • Reply
      Aniruddha Chaudhari
      November 14, 2017 at 4:16 am

      Welcome, Abram! I am glad as you find it useful for your coding practice.

      Happy Coding!

  • Reply
    Taylor
    June 10, 2020 at 11:43 am

    Hi!
    I know this is an old post, but are you able to tell me how to alter the python code in the cmd.py file to run the user’s open file?
    Like appending the actual filename to the path somehow?

    Thanks! This package is great!

    • Reply
      Kamlesh Prajapati
      May 6, 2022 at 4:52 pm

      Hi Taylor,

      I have changed the cmd.py as per my need. After changing to the current directory (where the file is present) I am running “python filename” to run the .py file.

      import os, sublime_plugin
      class CmdCommand(sublime_plugin.TextCommand):
          def run(self, edit):
              file_name=self.view.file_name()
              path=file_name.split("\\")
              current_driver=path[0]
              file = path.pop()
              current_directory="\\".join(path)
              command= "cd "+current_directory+" & "+current_driver+" & start cmd /k python " + file
              os.system(command)
      
      • Reply
        Aniruddha Chaudhari
        May 11, 2022 at 1:00 pm

        This is really interesting.

        Thanks Kamlesh for sharing this trick. This looks very useful.

  • Reply
    Bibek Aryal
    June 30, 2020 at 3:17 pm

    Thank You SO MUCH!
    You should create a Youtube Video for this.

    • Reply
      Aniruddha Chaudhari
      June 30, 2020 at 3:26 pm

      Thank you for your suggestion, Bibek.

      I’m already planning to launch our YouTube channel.

  • Reply
    Allen Kennedy
    March 16, 2021 at 6:40 am

    How do I get this to work? I see the cmd in right click menu, but clicking it does nothing.

    • Reply
      Aniruddha Chaudhari
      March 16, 2021 at 12:20 pm

      Looks like there is something wrong in cmd.py. Can you share the code from cmd.py file?

  • Reply
    Luiz Castro
    November 11, 2021 at 5:53 pm

    Could not make it work, the cmd does appear in the menu but it is greyed out.
    I used the same code you provided in this page.

    • Reply
      Aniruddha Chaudhari
      December 20, 2021 at 5:24 pm

      Exact same code works for me. May I know which OS you are using?

    • Reply
      Martin
      August 30, 2022 at 12:29 am

      Just type your folder name CMD in uppercase…
      this problem is also faced by me but now after doing this it works…
      I hope it works.
      thnx.

Leave a Reply Cancel reply

Interview Questions



You can share your interview experience.

Subscribe for FREE Newsletter

Do you want me to send you programing updates for FREE?

Subscribe below…

© 2022 – CSEstack.org. All Rights Reserved.

  • Home
  • Subscribe
  • Contribute Us
    • Share Your Interview Experience
  • Contact Us
  • About
    • About CSEstack
    • Campus Ambassador
  • Forum & Discus
  • Tools for Geek
  • LeaderBoard