Sublime Text from Command Line

前端 未结 27 1928
时光说笑
时光说笑 2020-11-27 08:37

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 s

相关标签:
27条回答
  • 2020-11-27 09:34

    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.

    worked fine in regular cmd and "command prompt with ruby and rails" cmd

    0 讨论(0)
  • 2020-11-27 09:34

    Going off the most accepted answer, but whose author unfortunately said modifying the PATH is "hard" - it's not at all. It's very easy. I just did it, and you can too!

    Here's what to do:

    Navigate to your sublime text directory in Windows Explorer and copy the full path from the path bar.

    For example, I have a few development tools set up as portable applications in Dropbox, so I copied the path:

    C:\Users\username\Dropbox\Programs\Sublime Text Build 3114 x64

    Go to Control panel-> System-> Advanced System Settings-> Environment Variables

    In the resulting window, navigate to "path" in the bottom window, highlight it and click "Edit".

    In the window that appears, click "New", paste in your Sublime Text path, and click "OK".

    Now open CMD or Powershell and type subl

    Sublime Text window should open. Enjoy!

    Note: I noticed someone else answered this in a similar fashion, but used a fixed location for Sublime Text. That may work for some people, but for others the directions will be erroneous. The fact is, the Sublime Text location can be anywhere on the drive, and knowing where it is and copying that particular location is one of the most important parts of assigning the PATH variable.

    0 讨论(0)
  • 2020-11-27 09:34

    Here is what worked for me in PowerShell:

    # CHECK IF YOUR ALIAS FOR SUBLIME TEXT 3 EXISTS
    Get-Alias subl
    
    # REMOVE YOUR ALIAS FOR SUBLIME TEXT 3 IF IT EXISTS
    # REF 1
    Remove-Item alias:subl
    
    # SET YOUR ALIAS FOR SUBLIME TEXT 3
    Set-Alias subl -Value "C:\Program Files\Sublime Text 3\sublime_text.exe"
    
    # CREATE A TEST FILE ON YOUR Desktop
    # REF 2
    echo "Testing`nNew`nFile`n." > $HOME\Desktop\TestFile.txt
    
    # TEST YOUR NEW ALIAS
    subl $HOME\Desktop\TestFile.txt
    

    This is the easiest way to set and test the alias. If you want to keep this against your profile try this:

    # TO PERMANENTLY KEEP EVERYTIME YOU OPEN POWERSHELL PLEASE ADD TO YOUR PROFILE. BUT FIRST VERIFY YOUR PROFILE `FILE` EXISTS, IF NOT THEN THIS WILL CREATE IT.
    # REF 3 & 4
    if (!(Test-Path -Path $PROFILE.CurrentUserAllHosts)) {New-Item -ItemType File -Path $PROFILE.CurrentUserAllHosts -Force}
    
    # open powershell PROFILE
    ise $PROFILE.CurrentUserAllHosts
    
    # Add the Set-Alias to your file
    Set-Alias subl -Value "C:\Program Files\Sublime Text 3\sublime_text.exe"
    

    REF 1 Remove-Alias: https://superuser.com/q/883914/247728

    REF 2 Newline: https://stackoverflow.com/a/36738723/1896134

    REF 3 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-5.1

    REF 4 https://devblogs.microsoft.com/scripting/understanding-the-six-powershell-profiles/

    Operating System (OS): Windows 10 Pro

    0 讨论(0)
  • 2020-11-27 09:35

    If your using Cmder, you can add the alias to your aliases file, which is located wherever you installed cmder to, then config\aliases

    You can then add ( this is for sublime text 3 )

    subl="C:\Program Files\Sublime Text 3\sublime_text.exe" $1
    

    From within Cmder, you can then open any directory in sublime via

    subl="C:\Program Files\Sublime Text 3\sublime_text.exe" $1
    
    0 讨论(0)
  • 2020-11-27 09:36

    I think that is more easy set the Environment variable in Windows.

    Then just add a new System variable called SUBLIME_HOME with value "C:\Program Files\Sublime Text 2\" (without quotes) after edit the variable Path adding in the end this value ";%SUBLIME_HOME%" (without quotes).

    Restart the git BASH and enjoy, using like this:

    $ sublime_text mi-new-file

    (where sublime_text is the command)

    Note: Also works now for cmd of Windows.

    0 讨论(0)
  • 2020-11-27 09:36

    Hollow every one.

    I build a very easy way to do this.

    project github page

    just download "install.bat" and right click on install.bat -> click "run as administrator"

    0 讨论(0)
提交回复
热议问题