简体   繁体   English

在 Windows 上的 Ubuntu 上从 Bash 打开 Sublime Text

[英]Opening Sublime Text from Bash on Ubuntu on Windows

I can't seem to figure out how to open Sublime Text 2 from Bash on Ubuntu on Windows.我似乎无法弄清楚如何在 Windows 上的 Ubuntu 上从 Bash 打开 Sublime Text 2。 Ultimately I would like to be able to use subl .最终我希望能够使用subl . to open the contents of the directory I am in.打开我所在目录的内容。

On my machine, Sublime Text 2 is installed at C:\\Program Files\\Sublime Text 2 .在我的机器上,Sublime Text 2 安装在C:\\Program Files\\Sublime Text 2 sublime_text.exe is located in this directory. sublime_text.exe位于此目录中。 In Bash on Ubuntu on Windows, I can access any files located on C through /mnt/c/ .在 Windows 上的 Ubuntu 上的 Bash 中,我可以通过/mnt/c/访问位于C上的任何文件。

I tried setting an alias: alias subl="/mnt/c/Program\\ Files/Sublime\\ Text\\ 2/sublime_text.exe" .我尝试设置别名: alias subl="/mnt/c/Program\\ Files/Sublime\\ Text\\ 2/sublime_text.exe" However, upon trying subl .但是,在尝试subl . I get the following error:我收到以下错误:

cannot execute binary file: Exec format error无法执行二进制文件:执行格式错误

How can I set this up properly?如何正确设置?

It's now possible to launch Windows executables (like Sublime Text) from the Bash on Ubuntu command line. 现在可以在 Ubuntu 命令行上从 Bash 启动 Windows 可执行文件(如 Sublime Text)。

You should also be able to set an alias to use it from the command line (as you were trying to do).您还应该能够设置别名以从命令行使用它(正如您尝试做的那样)。 Mine is as follows (and works fine):我的如下(并且工作正常):

alias subl='"/mnt/c/Program Files/Sublime Text 3/subl.exe"'

Note the second set of quotes: this is necessary because of the spaces in the file path.注意第二组引号:这是必要的,因为文件路径中有空格。 Alternatively you can escape the spaces (as you did in your example).或者,您可以转义空格(就像您在示例中所做的那样)。

Nick F's answer is correct, but there is an important caveat. Nick F 的回答是正确的,但有一个重要的警告。

If your intent is to edit Linux files using Sublime Text, then you should reconsider.如果您打算使用 Sublime Text 编辑 Linux 文件,那么您应该重新考虑。 Doing so can cause data corruption, as I've discovered first hand.正如我亲眼所见,这样做会导致数据损坏。

See here for more details on why: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/有关原因的更多详细信息,请参见此处: https : //blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

I realize this is an old post, but I'm hoping this will serve as a warning to other users attempting to set up Sublime Text to edit Linux files.我意识到这是一篇旧帖子,但我希望这可以作为对尝试设置 Sublime Text 以编辑 Linux 文件的其他用户的警告。

Creating alias will not let you use创建别名不会让你使用

subl path_to_file

instead, you can just link the subl application to your /bin folder相反,您可以将 subl 应用程序链接到您的 /bin 文件夹

 sudo ln -s /mnt/c/Program\ Files/Sublime\ Text\ 3/subl.exe /bin/subl

Done!!完成!!

If there is not /bin folder do whereis ls and replace /bin with the output directory如果没有 /bin 文件夹,请执行whereis ls并将 /bin 替换为输出目录

ps- /bin is a standard directory in Unix-like OS that contains the executable(short form of binaries) ps- /bin 是类 Unix 操作系统中的标准目录,其中包含可执行文件(二进制文件的缩写形式)

It can be done.这是可以做到的。

You can edit remote files with your local Sublimeusing RemoteSubl, a SublimeText plugin:您可以使用本地 Sublimeusing RemoteSubl(一个 SublimeText 插件)来编辑远程文件:

https://github.com/randy3k/RemoteSubl https://github.com/randy3k/RemoteSubl

Works out of the box for this scenario, and also takes care about diferent file subsystems don't messing around each other.在这种情况下开箱即用,并且还注意不同的文件子系统不会相互干扰。

If anyone wants to improve.. a condition to detects if the file is in the windows or linux realm, and lanch the appropiate editor... with a different theme... Geez!如果有人想改进.. 检测文件是否在 windows 或 linux 领域的条件,并启动适当的编辑器......使用不同的主题......天啊! that would be great.那太好了。

This one is working for me by adding it in .zshrc Debian in WSL with Windows 10 Pro通过将它添加到带有 Windows 10 Pro 的 WSL 中的 .zshrc Debian 中,这个对我有用

alias subl="/mnt/c/Program\\ Files/Sublime\\ Text\\ 3/sublime_text.exe"别名 subl="/mnt/c/Program\\ Files/Sublime\\ Text\\ 3/sublime_text.exe"

https://github.com/grigger/subl-wsl https://github.com/grigger/subl-wsl

Here's a more complete script I just wrote starting from some stackoverflow answers, that will open in sublime both files with Windows or Linux paths.这是我刚刚从一些 stackoverflow 答案开始编写的更完整的脚本,它将在 sublime 中打开两个带有 Windows 或 Linux 路径的文件。

ie subl ~/something will open sublime in C:\\Users\\<usr>\\AppData\\Local\\Packages\\...\\LocalState\\rootfs subl /mnt/d/something will open D:\\somethingsubl ~/something将在C:\\Users\\<usr>\\AppData\\Local\\Packages\\...\\LocalState\\rootfs subl /mnt/d/something将打开D:\\something

I know it's quite a while after the answer, but maybe some other folks will be helped by this in the future.我知道在回答之后还有很长一段时间,但也许将来会有其他一些人会得到帮助。

Just want to highlight to other users that there was indeed an update in WSL in May 2019, based on my reading it is now OK to edit Linux files from windows, as long as you use the 9P fileserver (eg \\\\wsl$\\ ).只是想向其他用户强调 2019 年 5 月 WSL 确实有更新,根据我的阅读,现在可以从 Windows 编辑 Linux 文件,只要您使用 9P 文件服务器(例如\\\\wsl$\\ ) . This is a HUGE improvement!这是一个巨大的改进!

Man this is a very simply thing, dont use Windows programs in Linux machines without something like Wine. 男人这是一个非常简单的事情,不要在Linux机器上使用Windows程序而不使用像Wine这样的东西。

Install SublimeText using the linux installation files according to your dist. 根据你的dist,使用linux安装文件安装SublimeText。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM