I'v created a function in VIM named OpenCMD(), it used for open command line or terminal in VIM (And cd in the current file path)
func! OpenCMD()
if has('win32')
let com = '!cmd /c start cd '. expand('%:p:h')
else
let com = '!/usr/bin/gnome-terminal --working-directory=' . expand('%:p:h')
endif
silent execute com
endfunc
nmap cmd :call OpenCMD()
Now, I want to open command line and cd in the current file path in Sublime (sublime 3 beta). The function as the same as the OpenCMD()
.
And I searched an question in stackover flow: Sublime Text 2 - Open CMD prompt at current or project directory (Windows)
I did as the the first guy answered (Create cmd, cmd.py and Context.sublime-menu). But it cannot work, the cmd operation always disabled.
Is there any way can get it? Thanks in advance!
Open Command Prompt in Windows 7Click the Windows Start Button. In the search box type cmd. In the search results, Right-Click on cmd and select Run as administrator (Figure 2). This will open the Command Prompt window (Figure 3).
Type 'Terminus' and select it. Wait for it to Complete installation and Restart sublime text. And save it. Note: The above code is for Linux users for Windows users you have to enter “cmd.exe” in place of “bash”, also here we kept the shortcut key as “alt+1” you can use your own key.
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.
The answer about Sublime Text 2 - Open CMD prompt at current or project directory (Windows) is nearly correct.
Only one step (for me) has to be changed is the file name should be uppercase. Use CMD
instead of cmd
.
%APPDATA%\Sublime Text 3\Packages
or just click
Preferences -> Browser Packages.. in sublime-text-3 Beta CMD
(Uppercase). The path of CMD should be %APPDATA%\Sublime Text 3\Packages\CMD
. cmd.py
(lowercase), paste the context as below: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)
Context.sublime-menu
. Add context as below:[
{ "command": "cmd" }
]
Of cause, if you want to open command line by command (by 'cmd' for example), you can add the following context into Default (Windows).sublime-keymap file. :
{ "keys": ["c", "m", "d"], "command": "cmd"}
You can open it from Preferences -> Key Bindings - User
You can install Terminal package in Sublime text 3 using the following steps.
Now when you right click on a file or folder you will see Open Terminal Here option
For Windows i replace the command with:
command= "cmd /K cd "+current_directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With