windows 命令行中的 Sublime 文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9440639/
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
Sublime Text from Command Line
提问by mehulkar
I installed Sublime Text and wanted to know how to open rb
files in it from the terminal. I saw What is the command to make Sublime Text my core editor?and I see that I can make Sublime my core editor, but I want to be able to type
我安装了 Sublime Text 并想知道如何rb
从终端打开其中的文件。我看到让 Sublime Text 成为我的核心编辑器的命令是什么?我看到我可以让 Sublime 作为我的核心编辑器,但我希望能够输入
sublime file.rb
How do I do this in Windows?
如何在 Windows 中执行此操作?
采纳答案by sandcastles
From build 3065(Release Date: 29 August 2014) onwards Sublime text
includes a command line helper, nameley subl.exe
. It is at sublime's installation folder: copy it in to a folder included in the system path.
For example, in my case I copied it
从 build 3065(发布日期:2014 年 8 月 29 日)开始,Sublime text
包含一个命令行助手 nameley subl.exe
。它在 sublime 的安装文件夹中:将其复制到系统路径中包含的文件夹中。例如,在我的情况下,我复制了它
from C:\Program Files\Sublime Text 3
从 C:\Program Files\Sublime Text 3
to C:\Windows\System32
到 C:\Windows\System32
You may then use in your terminal/console subl
as a command to open whatever file, such as in your example:
然后,您可以在终端/控制台subl
中将其用作打开任何文件的命令,例如在您的示例中:
subl file.rb
subl file.rb
Or you may as well modify your system PATH
variable to include sublime's instalation folder, but I believe that is much more involved.
或者你也可以修改你的系统PATH
变量以包含 sublime 的安装文件夹,但我相信这涉及更多。
回答by pjumble
Windows Command Prompt
Windows 命令提示符
For Windows cmd.exe you could just add the sublime text installation directory to your PATH environment variable, this would allow you to type:
对于 Windows cmd.exe,您可以将 sublime text 安装目录添加到 PATH 环境变量中,这将允许您键入:
sublime_text file.rb
Personally, I add a doskey(in a .bat file set to autorun with cmd) so I can type subl file.rb
:
就个人而言,我添加了一个doskey(在设置为使用 cmd 自动运行的 .bat 文件中),以便我可以输入subl file.rb
:
> doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*
Cygwin
赛格温
For the default bash shell add an alias to your ~/.bashrc
file, e.g:
对于默认的 bash shell,为您的~/.bashrc
文件添加一个别名,例如:
$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc
回答by Kristopher Johnson
I added this to my PowerShell profile:
我将此添加到我的PowerShell 配置文件中:
Set-Alias subl 'C:\Program Files\Sublime Text 2\sublime_text.exe'
Modify this as needed for Sublime Text 3 (or any future versions).
根据需要修改 Sublime Text 3(或任何未来版本)。
回答by John Nelson
Another idea would be to include C:\Program Files\Sublime Text 2\
in your PATH, and then run an administrator command prompt:
另一个想法是包含C:\Program Files\Sublime Text 2\
在您的 PATH 中,然后运行管理员命令提示符:
cd "C:\Program Files\Sublime Text 2\"
mklink sublime.exe sublime_text.exe
That will make a symbolic link with the new name. And now you can use it freely:
这将与新名称建立符号链接。现在您可以自由使用它:
sublime hello.txt
Update: After having a chance to use this trick and update Sublime Text 2, I'm happy to say that updating to a new build doesn't affect the symbolic link.
更新:在有机会使用这个技巧并更新 Sublime Text 2 之后,我很高兴地说更新到新版本不会影响符号链接。
回答by mblsha
I've created subl.bat in C:\Program Files\Sublime Text 2 with contents:
我在 C:\Program Files\Sublime Text 2 中创建了 subl.bat 内容:
start sublime_text.exe %*
Now that I have C:\Program Files\Sublime Text 2 in PATH, I can simply type 'subl folder' and it works wonderfully without having to add anything to autostart.
现在我在 PATH 中有 C:\Program Files\Sublime Text 2,我可以简单地输入“subl 文件夹”,它可以很好地工作,而无需添加任何东西来自动启动。
回答by glrodasz
I think that is more easy set the Environment variablein Windows.
我认为在 Windows 中设置环境变量更容易。
Then just add a newSystem variablecalled SUBLIME_HOMEwith value "C:\Program Files\Sublime Text 2\" (without quotes)after edit the variable Pathadding in the end this value ";%SUBLIME_HOME%" (without quotes).
然后在编辑变量Path后添加一个名为SUBLIME_HOME的新系统变量,其值为 "C:\Program Files\Sublime Text 2\" (不带引号),最后添加这个值 ";%SUBLIME_HOME%" (不带引号)。
Restart the git BASHand enjoy, using like this:
重新启动git BASH并享受,使用如下:
$ sublime_text mi-new-file
$ sublime_text mi-new-file
(where sublime_textis the command)
(其中sublime_text是命令)
Note:Also works now for cmd of Windows.
注意:现在也适用于 Windows 的 cmd。
回答by ben_joseph
Add the installation folder to windows path and you will be able to open Sublime by typing the name of the executable file, which is by default "subl
".
将安装文件夹添加到windows路径中,输入可执行文件的名称即可打开Sublime,默认为“ subl
”。
To include the Sublime installation folder in windows path,
要在 Windows 路径中包含 Sublime 安装文件夹,
- Open command prompt and type
sysdm.cpl
- In Advanced tab, select
Environment variables
- Under system variables, select variable named "
Path
" and clickEdit
. - Add "
C:\Program Files\Sublime Text 3;
" to the end of the existing string. - Save the changes and restartcommand prompt.
- 打开命令提示符并键入
sysdm.cpl
- 在高级选项卡中,选择
Environment variables
- 在系统变量下,选择名为“
Path
”的变量并单击Edit
。 - 将 "
C:\Program Files\Sublime Text 3;
"添加到现有字符串的末尾。 - 保存更改并重新启动命令提示符。
回答by Josh
I know this thread is a bit old, but I recently came up with this solution and thought I would share it...
我知道这个线程有点旧,但我最近想出了这个解决方案,并认为我会分享它......
If you use Cygwin, you can create a bash script that will convert the unix pathnames to windows paths and pass them to sublime. Paste the following into a new file:
如果您使用 Cygwin,您可以创建一个 bash 脚本,将 unix 路径名转换为 Windows 路径并将它们传递给 sublime。将以下内容粘贴到一个新文件中:
#!/bin/bash
/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe `cygpath -w $@` &
Save it in /usr/bin/subl
(or wherever you want so long as the location is in your $PATH
) and make it executable ($ chmod a+x /usr/bin/subl
)
将其保存在/usr/bin/subl
(或任何您想要的位置,只要该位置在您的 中$PATH
)并使其可执行 ( $ chmod a+x /usr/bin/subl
)
With this script, you can use both UNIX and Windows style paths (/cygdrive/c/
or C:/
) because the cygpath
utility converts the /
and ~
path aliases to their windows equivalents.
使用此脚本,您可以同时使用 UNIX 和 Windows 样式路径(/cygdrive/c/
或C:/
),因为该cygpath
实用程序会将/
和~
路径别名转换为其 Windows 等效项。
Now, you can use $ subl file1.txt file2.md ~/file3.txt
to open those files in sublime!
现在,您可以使用$ subl file1.txt file2.md ~/file3.txt
sublime 打开这些文件!
回答by pneumatics
The accepted answerdoesn't seem to work, at least for Sublime Text 3 on Windows 7. Copying the file directly into C:\Windows\System32
allows subl
to resolve fine from the shell, but when I run it, nothing happens.
该接受的答案似乎并没有工作,至少对崇高的文本3在Windows 7上直接复制到该文件C:\Windows\System32
允许subl
以解决罚款由壳体,但是当我运行它,什么都不会发生。
I've had more success with a hardlink:
我在硬链接方面取得了更大的成功:
mklink /h c:\windows\system32\subl.exe "c:\Program Files\Sublime Text 3\subl.exe"
mklink /h c:\windows\system32\subl.exe "c:\Program Files\Sublime Text 3\subl.exe"
With that, subl <file.txt>
and subl <directory>
both work fine.
就这样,subl <file.txt>
并且subl <directory>
都工作得不错。
回答by user1973194
I'm trying out ruby on rails in windows and include the PATH C:\Program Files\Sublime Text 2\
,then change the name sublime.exe
to subl.exe.
我正在 Windows 中的 rails 上尝试 ruby 并包含 PATH C:\Program Files\Sublime Text 2\
,然后将名称更改sublime.exe
为subl.exe.
worked fine in regular cmd and "command prompt with ruby and rails" cmd
在常规 cmd 和“带有 ruby 和 rails 的命令提示符”cmd 中运行良好