Sublime Text 2: Difference between revisions

From wikinotes
(No difference)

Revision as of 18:50, 2 May 2015

Sublime Text 2 is a text editor that comes with it's own built-in package manager. For the most part, SublimeText automatically detects the type of file you are writing to, and activates appropriate syntax highlighting

Hotkeys
CTRL + R
List Functions
CTRL + SHIFT + P
Enter Command (install package, markdown preview, etc)
ALT + SHIFT + NUM
Switch Column Views
CTRL + SHIFT + NUM
Move Window to Specific Column
CTRL + NUM
Select Column

Config Files

~/.config/sublime-text-2/Packages/User/Preferences.sublime-settings
SublimeText2 Userprefs main config
~/.config/sublime-text-2/Packages/Default (Linux).sublime-keymap
SublimeText2 UserKeyPrefs key config
## Packages:

Vintage Mode
VintageEx
Chain Of Command
sublimetext-syntaxfold
MayaSublime
Markdown Preview
LiveReload



Custom Plugins

getting started

Plugin Packaging Standards

/home/will/.config/sublime-text-2/Packages/MYPACKAGE/MYPACKAGE.py Sublime Packaging Standards

SublimeText uses python for all of it's plugins. In order for them to be discovered, you must place both a python script, and a folder of the same name in the packages folder.


Function Names and CamelCase
In order for sublimetext commands to be run from it's embedded python interpreter, they must be classes with each letter Capitalized followed by 'Command'. These classes receive one of sublimeText's premade objects( that define what type of information we are processing ). Then within that class, you need a method called 'run'.

Camelcase is a naming convention where the first letter of every word in a function name is capitalized. When running commands from sublime's interpreter: - the suffix of 'Command' is stripped - the entire string is made lowercase - each word is separated by a '_'

#### Example:
import sublime, sublime_plugin
             +-----------------------------------------------------------+
             |                                                           |
class MyExampleCommand(sublime_plugin.TextCommand):                      |
    def run(self, edit):                                                 |  (Same Command)
        self.view.insert(edit, 0, "Hello, World!")                       |
                                                                         |
                                                                         |
## You can then open sublimeText's python interpreter with (Ctrl + `)    |
## or 'View > View Console'                                              |
## and run the commmand.                                                 |
view.run_command("my_example")                                           |
                       |                                                 |
                       +-------------------------------------------------+



Packages/Extensions

Install Package Manager


## Push CTRL+~ to get the terminal
## Copy + Paste the following code

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')


Installing Packages


Here is an example of how to install a package

CTRL + SHIFT + P					# Gives you a UI line
Package Install					# Package Installer
Live Reload							# Search for package to install
** Enter


Vintage Mode, Vintage Ex


One of the best features of sublime text is the built-in ability to be run with vim-style hotkeys. combined with the code preview/drag bar, and the nice colours sublime text in vintage mode is easily THE choice of text editor, missing only the ability to be run within a terminal.

vintage-mode Preferences > User Settings:

"vintage_start_in_command_mode": true,
"ignored_packages":
  [
     //"Vintage"
  ]


Vintage Ex

Ctrl + Shift + P 
Install Package
vintage ex


Markdown


Markdown is a kind of short-form HTML. I have been considering implementing Markdown for free-form notes for my own personal research. It must be converted from Markdown to HTML for your browser to read it correctly. Markdown has several file extensions, but I prefer *.md

SublimeText2 Packages for Markdown:

LiveReload

Reloads your website in your browser when doc is saved

You must also install the Browser extensions: https://github.com/dz0ny/LiveReload-sublimetext2

MarkdownPreview

Converts your file from a .md to html, and loads it in the browser of your choice. Note that Live Reload + Markdown Preview work together, but it only refreshes once properly in windows. I will need to hit F5 for updates in the browser window

Markdown Syntax Highlighting

SublimeText2 does not come with full syntax highlighting for Markdown. This will fix it. Navigate to:

Code Changes
Markdown Addition to Colorscheme sublimetext2 markdown-syntax-highlight
Locations
Windows C:\Users\Will\AppData\Roaming\Sublime Text 2\Packages\Color Scheme - Default
Archlinux

Open the file, and paste the above code inside it just before <pre></array></pre>


Mel, PyMel


Git You'll need to install git, or git portable. Git portable works, but I've had some minimal problems with the portable version of git when integrating it into sublime text. Install where possible, or extract if no admin privileges.

http://code.google.com/p/msysgit/downloads/list

MayaSublime

Browse to sublime Text's package directory. If you aren't sure of it's location,

  • Sublime Text > Preferences > Browse Packages
  • Shift + rclick > Open CMD at current Location
## Local Git Install:
cd C:\Users\will\AppData\Roaming\Sublime Text 2\Packages
cd /home/will/.config/sublime-text-2/Packages
git clone git://github.com/justinfx/MayaSublime.git

## Portable Git Install:
cd C:\Users\will\AppData\Roaming\Sublime Text 2\Packages
"C:\users\will\Documents\~ Portable\Git\bin\git.exe" clone git://github.com/justinfx/MayaSublime.git

## If you are running this on a unix derivative, you may need to 
## make MayaSublime/MayaSublime.py executable with 'chmod +x MayaSublime.py'
#
## In order to execute commands from Sublime Text, you must 
## execute the following in Maya:
commandPort -n ":7001";




sublime-customfolding


cd /home/will/.config/sublime-text-2/Packages

git clone https://github.com/diametric/sublime-customfolding.git
cp -R /home/will/.config/sublime-text-2/Packages/sublime-customfolding/sublime_customfolding /home/will/.config/sublime-text-2/Packages/

### Settings - User
{ 
"customfolding_tags": [ ["{{{","}}}"] ], 
"customfolding_onload_all": true 
} 

### Package Settings > Settings - User
{ 
"in_process_packages": [], 
"installed_packages": ["sublime_customfolding"] 
}

I do have this working now, for everything except the final fold. It's a little buggy, but it will get people used to it... I guess...

https://github.com/diametric/sublime-customfolding.git



alignTab

Tabular for sublimeText:

https://github.com/randy3k/AlignTab

FileDiff


This allows you to create a diff file (patch file) with the changes between two files. This is not like using meld, it just creates a file you can use to patch another file.

Usage

  • Ctrl + Shift + P > FileDiffs:Menu > Diff file with open tab
  • This will create a new tab with the changes needed to make the current tab the same as the second open tab