Sublime Forum

How to Create Snippets + How to Change Font Size

#1

Hello,

I’m a new user to Sublime Text and really enjoying it for the most part. I asked Jon Skinner a few question via email regarding some of the program’s functionality and he was kind enough to answer. I’m going to post my questions and his responses here so that others searching the form with similar questions might benefit.

HOW TO CHANGE FONT SIZE / ADJUST FOR HIGH DPI SETTINGS
Allen Mackley wrote:

Hi, I just bought Sublime Text and I have a couple quick questions/concerns.

  1. How do I increase the font size of the text? I couldn’t find this option in the General Preferences file.
  2. I’m using a higher than normal DPI (125%) because I have a large screen resolution. However, because of this, some of the text on the programming interface, such as the names displayed on the tabs, bleeds outside of the visible area so that half of the text is cut off. Will this be fixed in an upcoming version, so that those with higher DPI settings will still be able to maintain the readably of the program?

Jon Skinner wrote:

  1. You can change the current font, by adding the line:

font Courier New 12

to Preferences/User File Preferences. You can see all available options by browsing through Preferences/Default File Preferences.

  1. I’m currently working on revamping some of the behind the scenes code to do with the GUI, and I’ll try to make it handle different DPI settings automatically then. It’ll be some time before this code makes it to a released version, however.

In the meantime, the sizes of several parts of the GUI can be adjusted by hand, so you should be able to customise it to work for you - the tab size can certainly be adjusted:

  1. Choose the menu item ‘Preferences/Browse Packages…’
  2. Navigate to the ‘Theme - Default’ directory
  3. Open the file in this directory, ‘Default.sublime-theme’
  4. Change the value of ‘size.tabHeaderHeight’ from 28 to something larger: 35 may be correct for you.
  5. Change other settings that you need to: you’ll likely want to increase the status bar height too.

Your changes should appear as soon as you save the file, so hopefully it’s not too painful.


HOW TO CREATE SNIPPETS / ABOUT DOCUMENTATION / COMMANDS:
Allen Mackley wrote:

Hi,
I’d like to figure out how to use snippets in Sublime Text, but am lost on how it works. What do I need to do to create a snippet or simply use a default snippet? Is there a list of them somewhere?

On another note, will there be better and more thorough documentation for Sublime Text in the future? As it is now, it seems like there’s a lot to this program that I’m not able to tap into because of a lack of info. Also, the website’s doc has a nice list of commands, but doesn’t explain very well how to actually use them. Where exactly do I place ‘insertCharacters “Hello World!\n”’ in order to get it to do something?


Jon Skinner wrote:

You can see the default snippets by browsing the Tools/Snippets menu.

You can create a snippet by choosing Tools/New Snippet, and saving the snippet in the folder it prompts you with (Packages/User). You’ll likely want to delete the … tag. For details on the syntax used for the … tag, at present the best reference is the TextMate manual (manual.macromates.com/en/snippets) - Sublime Text uses the same format.

The commands are intended to be bound to keys - you can see them in use via Preferences/Default Key Bindings.

At the moment, I’m working towards removing the need for documentation - my goal is to move away from editing text files for configuration, instead providing dialogs for editing preferences, key bindings, snippets etc. It’ll be some time till this work sees the light of day, but I feel it’s the best long term solution.


Allen Wrote:

I appreciate you taking the time to help me out. It sounds like Sublime Text has a lot of development ahead of it still, and that’s okay. I once used a program called Texter that allowed me to insert a keyword, such as “doctype” (for HTML) and then hit the tab key and it would instantly replace that text with my predefined snippet. I’m assuming Sublime Text allows me to do the same thing, but that the functionality it’s built into the editor itself. I’ve figured out how to tweak the default preferences a little, but I’m not sure how to bind keywords to snippets in that way. I read the documentation you gave me a link to, but it didn’t help much. Could you give me an example? For example, how would you add and use a snippet for an HTML doctype:

I have another question, I hope you don’t mind. What is the console for and how is it intended to be used within Sublime Text? What is the Output Panel for and how does it differ from the Console?


Jon Wrote:

Save this into a .sublime-snippet file, in Packages/User (where the packages directory is the one that appears when you select Preferences/Browse Packages):

<![CDATA[

$0

]]> doctype

The tabTrigger element is what makes the key binding: after saving this, you should be able to type “doctype” then tab, and the snippet will be inserted. It will also be available by the menu command Tools/Snippets/User/. The “$0” portion of the snippet is where the cursor will be after inserting the snippet.

The console is there mainly for use when writing python plugins: you can enter python commands there, and that’s where the output of print statements within plugins get sent.

The output panel captures the output of build commands (i.e., what happens when you press F7).

0 Likes

#2

Strange… I use 175% with Consolas 12 in my living room and I don’t have any problem. It’s running on Windows 7 RC, the DPI scaling might be different.

0 Likes

#3

Thanks for this, stumbled across sublime this morning and I love it!

Side map, custom snippets and beautiful interface. Added the zen coding plugin. I know it’s sad but this has made my day

0 Likes