我安装了Sublime Text,想知道如何从终端打开其中的rb文件。我看到让Sublime Text成为我的核心编辑器的命令是什么?我看到我可以让Sublime成为我的核心编辑器,但我想要能够打字

sublime file.rb

在Windows中如何做到这一点?


当前回答

Windows命令提示符

对于Windows cmd.exe,你可以添加崇高的文本安装目录到你的PATH环境变量,这将允许你输入:

sublime_text file.rb

就我个人而言,我添加了一个doskey(在.bat文件中设置为自动运行cmd),这样我就可以键入subl file.rb:

> doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*

Cygwin

对于默认的bash shell,为~/添加一个别名。Bashrc文件:

$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc

其他回答

    @echo off
    :: File: TextFiles.Starter.DESKTOP-M175NUE.cmd v1.1.0 docs at the end 

    :: this just an iso-8601 wrapper for windows:
    :: src: http://www.cs.tut.fi/~jkorpela/iso8601.html
    call GetNiceTime.cmd

    :: go the run dir
    cd %~dp0z

    :: this is the dir containing the batch file
    set _MyDir=%CD%

    :: look around , set vars
    for %%A in (%0) do set _MyDriveLetter=%%~dA
    for %%A in (%0) do set _MyPath=%%~pA
    for %%A in (%0) do set _MyName=%%~nA
    for %%A in (%0) do set _MyEtxtension=%%~xA

    :: contains absolute file paths of the files to open like this
    set _ListFile=%_MyDir%\%_MyName%.lst
    :: example of lines in the list file - take out the ::space
    :: C:\Users\ysg\Desktop\TextFiles.Starter.DESKTOP-M175NUE.cmd
    :: C:\Users\ysg\Desktop\TextFiles.Starter.DESKTOP-M175NUE.lst


    :: set _Program="C:\Program Files\TextPad 8\TextPad.exe"
    set _Program="C:\Program Files\Sublime Text 3\sublime_text.exe"
    set _
    :: DEBUG PAUSE

    :: sleep 2
    ping -n 2 www.google.com > NUL

    :: for each line of the cat file do open 
    :: for TextPad , obs note the quoting 
    :: for /f "tokens=*" %%i in ('type "%_ListFile%"') do ^
    :: cmd /c "%_Program% "%%i""

    :: for sublime, obs note the quoting 
    for /f "tokens=*" %%i in ('type "%_ListFile%"') do ^
    cmd /c "%_Program% -t "%%i""
    :: DEBUG PAUSE

    :: Purpose: 
    :: to start a list of non-binary files from a list file on Windows 10
    :: Tested on Windows 10, should work on Win7 too
    :: 
    :: Requirements:
    :: TextPad 8 or Sublime
    :: 
    :: 
    :: Usage: 
    :: copy this file onto your Desktop, list the absolute paths in to the list file 
    :: change the program name in the _Program if if you want other editor
    :: 
    :: VersionHistory: 
    :: 1.1.0 --- 2017-10-06 09:42:54 --- ysg --- added sublime 
    :: 1.0.1 --- 2013-04-15 08:19:10 --- ysg --- added - todo-%today%.txt file opening
    :: 1.0.0 --- 2012-05-23 09:08:57 --- ysg -- Initial creation 

Windows命令提示符

对于Windows cmd.exe,你可以添加崇高的文本安装目录到你的PATH环境变量,这将允许你输入:

sublime_text file.rb

就我个人而言,我添加了一个doskey(在.bat文件中设置为自动运行cmd),这样我就可以键入subl file.rb:

> doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*

Cygwin

对于默认的bash shell,为~/添加一个别名。Bashrc文件:

$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc

创建注册表:

微软HKEY_LOCAL_MACHINE \ SOFTWARE \ \ Windows \ CurrentVersion \ \ sublime.exe应用路径

将默认参数REG_SZ的值更新为:

C:\Program Files\Sublime文本2\sublime_text.exe

我已经创建了sub .bat在C:\Program Files\Sublime文本2的内容:

start sublime_text.exe %*

现在我在PATH中有C:\Program Files\Sublime Text 2,我可以简单地键入“subl文件夹”,它工作得很好,无需添加任何东西来自动启动。

公认的答案似乎不管用,至少对Windows 7上的Sublime Text 3来说是这样。将文件直接复制到C:\Windows\System32允许subl从shell中很好地解析,但当我运行它时,什么都没有发生。

我用硬链接更成功:

mklink /h c:\windows\system32\sub .exe" c:\Program Files\Sublime Text 3\sub .exe"

这样,subl <file.txt>和subl <directory>都可以正常工作。