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

sublime file.rb

在Windows中如何做到这一点?


当前回答

添加Sublime的安装文件夹到你的路径。 @set PATH=C:\Program Files\Sublime Text 3;%PATH%

or

要在Windows中永久地设置一个环境变量(以便它对所有Windows进程可用),

start the "Control Panel" ⇒ "System" ⇒ (Vista/7/8) "Advanced system settings" ⇒ Switch to "Advanced" tab ⇒ "Environment variables" ⇒ Choose "System Variables" (for all users) or "User Variables" (for this login user only) ⇒ Choose "Edit" (for modifying an existing variable) or "New" (to create a new variable) ⇒ Enter the variable "Name" and "Value".

在这种情况下,在路径前加上C:\Program Files\Sublime Text 3。

现在,可以将'sublime_text.exe'复制为'sublime_text.exe'

然后在任何命令提示符中,您都可以运行file.txt文件

C:\Users\MyUsername>sublime filename.txt

其他回答

经过长时间的尝试,下面的步骤对我有效。

创建PowerShell配置文件 使用如下命令: 如果(!(Test-Path -Path)) { New-Item -ItemType文件-Path $PROFILE。CurentUserAllHosts force } 编辑配置文件

您可以在文本编辑器(如记事本)中打开任何PowerShell配置文件。

打开当前PowerShell主机中当前用户的配置文件 应用程序在记事本,键入:

>notepad $PROFILE.CurentUserAllHosts

在记事本上,将以下命令粘贴到配置文件中 Set-Alias subl -Value "C:< sublime_text.exe在您PC上的路径" 要应用更改,保存概要文件,然后重新启动PowerShell。 现在在Powershell上,cd你选择的目录并输入: subl。 例如, $newfile subl。

在环境变量中,我也将%SUBLIME_HOME%变量添加到路径变量中 然后从我的命令终端做了一个符号链接

mklink sb sublime_text.exe

我认为在Windows中设置环境变量更容易。

然后只需添加一个名为SUBLIME_HOME的新系统变量,值为“C:\Program Files\Sublime Text 2\”(不带引号),在编辑变量Path后添加这个值“;%SUBLIME_HOME%”(不带引号)。

重新启动git BASH,使用如下代码:

$ sublime_text mi-new-file

(其中sublime_text是命令)

注意:现在也适用于Windows的cmd。

另一个想法是在你的PATH中包含C:\Program Files\Sublime Text 2\,然后运行管理员命令提示符:

cd "C:\Program Files\Sublime Text 2\"
mklink sublime.exe sublime_text.exe

这将与新名称建立符号链接。现在你可以自由使用它了:

sublime hello.txt

更新:在有机会使用这个技巧并更新Sublime Text 2后,我很高兴地说更新到新的版本并不会影响符号链接。

    @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