Is there a increaseIndentPattern in Sublime Text? - sublimetext2

I'm trying to add auto increate indentation feature in a Sublime Text package.
As for TextMate, there's increaseIndentPattern = '\{'; that can make easy indentation.
http://manual.macromates.com/en/appendix#indentation_rules
How can I do that in SUblime Text?

Sublime Text 2 already has easy indentation built in.
Hit Ctrl+] to indent right, and Ctrl+[ to indent back or remove indentation.
Similarly, you can select the text you want to indent, and hit the Tab key. This indents the selected block of text. Shift+Tab will remove indentation of selected text.
If you are working with predefined syntaxes you can define a keybinding for your "ReIndent" command, which will execute Edit>Line>Reindent command on the entire document.
However, if you reeeeally want to get your hands dirty with setting up how the program indents specific language syntaxes, you go to the Preferences Menu and hit Browse Packages.
Look for the language you want to modify indentation rules for, I'll use PHP as an example. There are 2 files that have indentation rules for my copy of PHP right now. Their names are as follows:
Indentation Rules Annex.tmPreferences
Indentation Rules.tmPreferences
There should be another copy of these same filenames with *.cache at the end. Feel free to add .old after .cache and modify the plain *.tmPreferences ones.

Related

Add HTML tags to selected text

Sounds simple but I really can't find the answer. I would like to be able to select text and add a tag without typing opening/closing tags manually, because it's a waste of time.
<p> selected text </p>
<ul>
<li> selected text </li>
<li> selected text </li>
...
What comes to my mind are workarounds like Notepad++ (find & replace) or Autohotkey scripts (copy, add tags and paste) + StrokesPlus mouse gestures.
Is there any editor where I could do it quickly with a shortcut? I'm new to HTML and I just want to find the most efficient solutions.
Many editors support this feature and if not, there are mostly extensions you can add for html language support.
In sublime-text for example if you write div then hit the tab-key you get <div></div> with the cursor positioned within the div scope, which makes life way easier.
One other solution that you might find interesting is writing with the template engine Jade. Just have a look its pretty straight forward.
With notepad++
if you want to change some lines as list ( < li > )
Select your text and press CTRL+H (to replace)
write in the first input (find what): (.*)
and in the second input (replace with):
< li >\1< /li >
check in the options: "In selection" and "regular expression"
Finaly click on replace all
You can use emmet with the editors that emmet supports, to create a tag you only need to type the word that you want to create and press Tab.
I love brakets editor; if you´re editing html code it has a live mode to view in real time the changes in your document.

Sublime Text: Accept Suggested Autocomplete Without Expanding it

In Sublime Text, I have installed Emmet so that I can do zen coding. Now, the problem is that when I'm typing, and get an autocomplete suggestion, as soon as I accept that autocomplete suggestion (either by entering tab, enter, or even pressing space bar), the suggested tag is expanded; this causes me not to be able to continue the zen coding.
To give you an example, say I want to insert a <select> with 6 <option> child elements. If I enter select>opt, then autocomplete suggests option, but as soon as I accept option, that expands to select<option></option>.
What I want is to accept option, but that it won't expand to <option></option>.
Is there anyway to accomplish this?
Actually, the answer is very simple. In your example, when you get the autocomplete suggestions for option, you will get 2 of them. One is the tag, the other is text. Use Ctrl+Space to go through all the suggestions, and select the text version of option and not the tag version.
In Sublime Text completions consists of a 2-tuple containing the showed string and the inserted characters/snippet. I don't think know whether it is possible to just insert the showed string. However if you search for any way, there is a way to establish: modify the source code of the html tag completion file.
Install PackageResourceViewer, then press ctrl+shift+p write PackageResourceViewer: Open Resource. Select HTML >>> html_completions.py.
If you save the file it will shadow (not overwrite) the original completions file. Hence just remove it to get the original behavior.
In this file:
in line 15 replace return (tag + '\tTag', tag + '>$0</' + tag) by return (tag + '\tTag', tag).
in line 245 replace completion_list = [(pair[0], '<' + pair[1]) for pair in completion_list] by completion_list = [(pair[0], pair[1]) for pair in completion_list]
Now it should insert the tag names instead of the whole tags.

How do I make custom snippets for Sublime Text 2 that use the same indentation as the current file?

Different projects can use different indentation styles (2-4 spaces, tabs) and I want my custom snippets to follow the style of the current file. The built-in Ruby snippets does this but my custom snippets retain the indentation of the snippet. I checked the docs and found the predefined variables:
$TM_SOFT_TABS YES if translate_tabs_to_spaces is true, otherwise NO.
$TM_TAB_SIZE Spaces per-tab (controlled by the tab_size option).
But I can't really see how to make use of those to control which indents to use.
Just use the tab character for indents in snippet files. Sublime Text will automatically convert them to the correct indentation style for the current file.

Format Code In MonoDevelop

I am using MonoDevelop on Mac to write MonoTouch apps. Automatica code indenting/formatting works great while I am typing.
The problem is that when I copy and paste code snippets, in many cases I lose the formatting and lines are combined together, indenting is lost, and it is a huge pain to implement the tabs, spacing, and line breaks manually. Is there anyway I can use a command in monoDevelop to automatically indent and apply the formatting to existing code.
I thought maybe Edit|Format|Format Document/Selection would work, but these commands don't have any affect on the code at all.
Any help?
To format the entire document in one keystroke: control-I
To format a selection: Edit->Format->Format Selection
To customize the formatting: MonoDevelop->Preferences->Source Code->Code Formatting
You actually need to select all your text, and then go to Edit->Format->Format Document. It doesn't seem to work otherwise.
For me on macOS, the shortcut for "auto-format" is CTRL + i.
You can change the shortcut if you want. To change it, go to Preferences -> Key Bindings, then type "format" in the search box and edit the "Format Document" shortcut/key binding.

Indenting by spaces using HTMLTidy in Notepad++

How do I make it so that instead of indenting my elements by multiples of 2 spaces (when formatting without wrapping is selected), HTMLTidy indents them by multiples of tabs (4 spaces long but only 1 byte in size)?
The HTML Tidy docs say that tidy never outputs tabs. But, since you're in Notepad++, you can use TextFX Edit -> Leading space to tabs to convert the spaces that HTMLTidy gives you into tabs. Just make sure that indent-spaces is set to 4 in your config file.
The location of your config file will vary depending on how you installed notepad++ and what version you have, but its path will probably look like one of these
C:\Program Files\Notepad++\plugins\NPPTextFX\tidycfg.ini
C:\Program Files\Notepad++\plugins\Config\tidy\tidycfg.ini