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

sublime file.rb

在Windows中如何做到这一点?


当前回答

我只是以管理员身份运行命令提示符程序,并执行以下命令。 简单,但对我有用。

echo "c:\Program Files\Sublime Text 3\subl.exe" %1 > %systemroot%\system32\subl.bat

当然,您可以任意调用bat文件。从那时起,作为任何用户,你可以简单地使用:

subl myfile.txt

其他回答

    @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 

我想从命令行开始一个Sublime Text的新实例。下面的页面帮助了我,尽管它只说OSX: http://www.sublimetext.com/docs/3/osx_command_line.html。

所以,我在用户路径中使用批处理文件来启动“sublime”。以下是我使用的基本内容(**批处理文件内容):

@start "sublime" "%~dp0Sublime Text\sublime_text.exe" --new-window %*

(我的批处理文件%~-dp0位于Sublime Text安装路径上方的一个文件夹。)

我知道这是一个旧的帖子,但我想我应该添加我正在寻找(并找到)的内容。它可能会帮助其他人!

将安装文件夹添加到windows路径下。


- Click on windows button 
- Type advance system settings in search box
- Click on the result (View Advance System Setting)
- Click on the Environment Variable Button at the Bottom right
- Go to System Variable Section Second
- Search for Path 
- Click on Path and Click on Edit Button 
- Click on New on right sidebar 
- Copy the Folder Path of Sublime Text Editor Sample(C:\Program Files\Sublime Text 3)
- Paste on New Line on Environment Variable
- Click on OK on Every Dialog Box
- All Set Now Follow below Steps

如果打开,则关闭CMD,或者启动新的CMD。 进入你的项目文件夹。 在Windows文件资源管理器中单击“地址”行。 全选并输入CMD。 它将在CMD中打开项目文件夹。 然后输入subl。//不要忘记添加 在(subl) ex (subl .)后面加点(.) 所有这些都完成了,它将在sublime文本编辑器中打开项目。

我知道这个帖子有点老了,但我最近想出了这个解决方案,我想分享它……

如果您使用Cygwin,您可以创建一个bash脚本,将unix路径名转换为windows路径并将它们传递给sublime。将以下内容粘贴到新文件中:

#!/bin/bash

/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe `cygpath -w $@` &

将其保存在/usr/bin/subl(或任何你想要的位置,只要位置在你的$PATH中),并使其可执行($ chmod a+x /usr/bin/subl)

使用这个脚本,您可以同时使用UNIX和Windows样式的路径(/cygdrive/c/或c:/),因为cygpath实用程序将/和~路径别名转换为它们的Windows等效路径。

现在,您可以使用$ subl file1.txt file2。Md ~/file3.txt以sublime方式打开这些文件!

如果你不想改变你的路径,你可以将文件与sublime关联。右键单击文件,单击属性,然后单击打开sublime text。

从命令行: myFile.py

将打开崇高的文件。我想这可以帮你省下5次按键。