Sublime Text 2 is free of installation. You can download and decompress it. The decompress path here is/home/fhp/App/SublimeText2.
To open a file using sublime directly on the terminal, add a soft link:
The code is as follows: |
|
Sudo ln-s/home/fhp/App/SublimeText2/sublime_text/usr/bin/sublime |
Add a desktop:
The code is as follows: |
|
Sudo sublime/usr/share/applications/sublime. desktop [Desktop Entry] Version = 1.0 Name = Sublime Text 2 GenericName = Text Editor Exec = sublime Terminal = false Icon =/home/fhp/App/SublimeText2/Icon/48 × 48/sublime_text.png Type = Application Categories = TextEditor; IDE; Development X-Ayatana-Desktop-Shortcuts = NewWindow [NewWindow Shortcut Group] Name = New Window Exec = sublime-n TargetEnvironment = Unity |
Modify file Association:
The code is as follows: |
|
Edit sudo sublime/usr/share/applications/defaults. list: Replace all gedit. desktop in the file with sublime. desktop. |
Some friends may encounter problems. After installing sublime text 2, they found that there was no option similar to "open file with Sublime Text 2" in the right-click menu.
Do not want to Open the File from the command line every time, or first Open Sublime Text 2 and then in "Open File", you have to write the script
Step 3:
1. First, the terminal enters ~ /. Gnome2/nautilus-scripts create a file without a suffix (here, the file name is the name in the right-click menu), and my file name is "Sublime-Text-2 ";
2. Then, add the following code:
# Use The Sublime Text 2 editor to open a file
The code is as follows: |
|
#! /Bin/bash IFS =' ' I = 1 For url in $ NAUTILUS_SCRIPT_SELECTED_URIS Do If [-n "'echo $ url | grep 'file: //'' "]; then Sublime 'echo "$ NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | cut-f $ I-D' ''& Else Sublime "$ url "& Fi I = $ ($ I + 1 )) Done |
Here, append another script file that can "open the file as administrator", the file name I used is "SU-Sublime-Text-2"
# Use The Sublime Text 2 editor as an administrator to open a file
The code is as follows: |
|
#! /Bin/bash IFS =' ' I = 1 For url in $ NAUTILUS_SCRIPT_SELECTED_URIS Do If [-n "'echo $ url | grep 'file: //'' "]; then Gksu sublime 'echo "$ NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | cut-f $ I-D' '' Else Gksu sublime "$ url" Fi I = $ ($ I + 1 )) Done |
3. Add the executable permission to the script file:
Chmod + x script file name
After logging on again or restarting Nautilus, right-click a file and you will see "Sublime-Text-2" and "SU-Sublime-Text-2" under the "script" option ".
PS: The four environment variables provided by Nautilus are:
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS: Path of the selected file separated by a new line (unless it is a local file)
NAUTILUS_SCRIPT_SELECTED_URIS: URI of the selected file separated by a new line
NAUTILUS_SCRIPT_CURRENT_URI: URI of the current location
NAUTILUS_SCRIPT_WINDOW_GEOMETRY: location and size of the current window