windows 如何在 windows7 中从 Sublime 打开命令行提示符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18606682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I open command line prompt from Sublime in windows7
提问by Marslo
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)
我在 VIM 中创建了一个名为 OpenCMD() 的函数,它用于在 VIM 中打开命令行或终端(以及当前文件路径中的 cd)
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()
.
现在,我想在 Sublime(sublime 3 beta)的当前文件路径中打开命令行和 cd。功能与OpenCMD()
.
And I searched an question in stackover flow: Sublime Text 2 - Open CMD prompt at current or project directory (Windows)
我在 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.
我是第一个回答的人(创建 cmd、cmd.py 和 Context.sublime-menu)。但它不起作用,cmd操作总是被禁用。
Is there any way can get it? Thanks in advance!
有什么办法可以得到吗?提前致谢!
回答by Marslo
The answer about Sublime Text 2 - Open CMD prompt at current or project directory (Windows)is nearly correct.
关于Sublime Text 2 - Open CMD prompt at current or project directory (Windows)的答案几乎是正确的。
Only one step (for me) has to be changed is the file name should be uppercase. Use CMD
instead of cmd
.
只有一步(对我来说)必须更改的是文件名应该是大写的。使用CMD
代替cmd
。
My steps (Win7):
我的步骤(Win7):
- Open folder
%APPDATA%\Sublime Text 3\Packages
or just click Preferences-> Browser Packages..in sublime-text-3 Beta - Create a folder named
CMD
(Uppercase). The path of CMDshould be%APPDATA%\Sublime Text 3\Packages\CMD
. - Open the folder CMD, and create a file, named
cmd.py
(lowercase), paste the context as below:
- 打开文件夹
%APPDATA%\Sublime Text 3\Packages
或在 sublime-text-3 Beta 中单击 Preferences-> Browser Packages.. - 创建一个名为
CMD
(大写)的文件夹。CMD的路径应该是%APPDATA%\Sublime Text 3\Packages\CMD
. - 打开文件夹CMD,并创建一个名为
cmd.py
(小写)的文件,粘贴上下文如下:
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)
- Create a file (again), named
Context.sublime-menu
. Add context as below:
- 创建一个文件(再次),命名为
Context.sublime-menu
. 添加上下文如下:
[
{ "command": "cmd" }
]
- The Cmd function will work in context menu(right-click). For example:
- Cmd 功能将在上下文菜单中工作(右键单击)。例如:
Of cause, if you want to open command lineby command (by 'cmd' for example), you can add the following context into Default (Windows).sublime-keymapfile. :
当然,如果您想通过命令(例如通过 'cmd')打开命令行,您可以将以下上下文添加到Default (Windows).sublime-keymap文件中。:
{ "keys": ["c", "m", "d"], "command": "cmd"}
You can open it from Preferences-> Key Bindings - User
您可以从Preferences-> Key Bindings - User打开它
回答by Ali
You can install Terminalpackage in Sublime text 3 using the following steps.
您可以使用以下步骤在 Sublime text 3 中安装终端包。
- Click on Package Controlin Preferences.
- Select Install Package.
- Search "Terminal" in the packages list then install it.
- 点击包控制在 首选项。
- 选择安装包。
- 在软件包列表中搜索“终端”然后安装它。
Now when you right click on a file or folder you will see Open Terminal Hereoption
现在,当您右键单击文件或文件夹时,您将看到在此处打开终端选项
回答by Oleg alex
For Windows i replace the command with:
对于 Windows,我将命令替换为:
command= "cmd /K cd "+current_directory
回答by math2001
Thank you so much @Marslo! But, I think we can improve the plugin a bit... (i"m on st3 beta, window 8)
非常感谢@Marslo!但是,我认为我们可以稍微改进插件......(我在 st3 beta,窗口 8)
import os
import sublime_plugin
class CmdCommand(sublime_plugin.TextCommand):
def run(self, edit):
os.system("cd " + self.view.file_name() + " & start cmd")
回答by gia huy
[Bonus]
[奖金]
As @Alipointed out in his solution and my comment was below.
正如@Ali在他的解决方案中指出的,我的评论如下。
If you want activate Command Promptinstead PowerShell, you can:
如果您想激活命令提示符而不是PowerShell,您可以:
{
// Replace with your own path to cmder.exe
"terminal": "terminal": "C:\Windows\system32\cmd.exe", // On my Windows 10 machine
"parameters": ["/START", "%CWD%"]
}
as be suggested as here
正如这里所建议的那样