Home:ALL Converter>Opening Sublime Text from Bash on Ubuntu on Windows

Opening Sublime Text from Bash on Ubuntu on Windows

Ask Time:2016-10-19T23:17:22         Author:Sara Fuerst

Json Formatter

I can't seem to figure out how to open Sublime Text 2 from Bash on Ubuntu on Windows. Ultimately I would like to be able to use 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.exe is located in this directory. In Bash on Ubuntu on Windows, I can access any files located on C through /mnt/c/.

I tried setting an alias: alias subl="/mnt/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe". However, upon trying subl . I get the following error:

cannot execute binary file: Exec format error

How can I set this up properly?

Author:Sara Fuerst,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40135502/opening-sublime-text-from-bash-on-ubuntu-on-windows
Sam D :

Nick F's answer is correct, but there is an important caveat.\n\nIf your intent is to edit Linux files using Sublime Text, then you should reconsider.\nDoing so can cause data corruption, as I've discovered first hand.\n\nSee 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/\n\nI 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.",
2017-08-08T16:27:00
Aakash Dantre :

Creating alias will not let you use \n\nsubl path_to_file\n\n\ninstead, you can just link the subl application to your /bin folder\n\n sudo ln -s /mnt/c/Program\\ Files/Sublime\\ Text\\ 3/subl.exe /bin/subl\n\n\nDone!!\n\nIf there is not /bin folder do whereis ls and replace /bin with the output directory\n\nps- /bin is a standard directory in Unix-like OS that contains the executable(short form of binaries)",
2020-04-07T07:22:33
elMestre :

It can be done.\n\nYou can edit remote files with your local Sublimeusing RemoteSubl, a SublimeText plugin:\n\nhttps://github.com/randy3k/RemoteSubl\n\nWorks out of the box for this scenario, and also takes care about diferent file subsystems don't messing around each other.\n\nIf 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! that would be great.",
2019-03-18T22:16:35
grigger :

https://github.com/grigger/subl-wsl\n\nHere'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. \n\ni.e. subl ~/something will open sublime in C:\\Users\\<usr>\\AppData\\Local\\Packages\\...\\LocalState\\rootfs\nsubl /mnt/d/something will open D:\\something\n\nI know it's quite a while after the answer, but maybe some other folks will be helped by this in the future.",
2020-04-09T13:04:44
Jonathan :

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 (e.g \\\\wsl$\\). This is a HUGE improvement!",
2020-04-16T19:36:00
Nick F :

It's now possible to launch Windows executables (like Sublime Text) from the Bash on Ubuntu command line.\nYou 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):\nalias subl='"/mnt/c/Program Files/Sublime Text 3/subl.exe"'\n\nNote 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).",
2017-01-27T15:55:02
yy