如何在Windows7中从Sublime打开命令行提示符 [英] How can I open command line prompt from Sublime in windows7

查看:172
本文介绍了如何在Windows7中从Sublime打开命令行提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VIM中创建了一个名为OpenCMD()的函数,用于在VIM中打开命令行或终端(以及当前文件路径中的cd)

 功能!如果有('win32')
,则OpenCMD()
let com =‘!cmd / c start cd’。 expand(’%:p:h’)
其他
let com =‘!/ usr / bin / gnome-terminal --working-directory =’。 expand('%:p:h')
endif
静默执行com
endfunc
nmap cmd:call OpenCMD()

现在,我想在Sublime(sublime 3 beta)的当前文件路径中打开命令行和cd。该功能与 OpenCMD()相同。


我在stackover流中搜索了一个问题:几乎是正确的。



(对我而言)只需更改一个步骤,文件名应为大写。使用 CMD 代替 cmd






我的步骤(Win7):




  • 打开文件夹%APPDATA%\Sublime在Sublime-text-3 Beta
  • 中输入文本3\Packages 或单击
    首选项-> 浏览器软件包。。 >
  • 创建一个名为 CMD 的文件夹(大写)。 CMD 的路径应为%APPDATA%\Sublime Text 3\Packages\CMD

  • 打开文件夹 CMD ,并创建一个名为 cmd.py 的文件(小写),粘贴以下内容:



  import os,sublime_plugin 
类CmdCommand(sublime_plugin.TextCommand):
def运行(自我,编辑):
file_name = self.view.file_name()
path = file_name.split( \\ )
current_driver = path [0]
path.pop()
current_directory = \\ .join(path)
命令= cd + current_directory + & + current_driver +&启动cmd
os.system(命令)




  • (再次)创建一个名为 Context.sublime-menu 的文件。添加如下内容:



  [
{ command: cmd }
]




  • Cmd函数将在上下文菜单(右键单击)。例如:



当然,如果要通过命令(例如以 cmd打开)打开命令行,则可以将以下上下文添加到 Default(Windows)中。 sublime-keymap 文件。 :

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

您可以从首选项-> 键绑定-用户


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!

解决方案

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.


My steps (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 CMD should be %APPDATA%\Sublime Text 3\Packages\CMD.
  • Open the folder CMD, and create a file, named 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)

  • Create a file (again), named Context.sublime-menu. Add context as below:

[
     { "command": "cmd" }
]

  • The Cmd function will work in context menu (right-click). For example:

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

这篇关于如何在Windows7中从Sublime打开命令行提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆