Sublime Text 2: soft wrap lines -> reverse indentation? - sublimetext2

I've started using Sublime Text 2, and its community of plugins, as my Dreamweaver replacement (thank the Gods). I love Sublime and clearly won't realize many of its features for months or years to come, but there's a simple setting I've had trouble figuring out.
I've used BBedit lots in the past. One feature I'm very attached to is the ability to "reverse" indent lines when soft-wrapped, such that line wrapping looks like this:
Text text blah blah blah blah long enough to wrap
to a new line blah whenever soft wrap happens it
reverse-indents like this.
Here's a new line with no indent.
Maybe I shouldn't be so married to a seemingly minor feature, but I find it much easier to read code when it's not possible to confuse the beginning of a line with "tailings" of a long line. Does anyone know how to do this in Sublime?

After further use, I think I've figured this out. Apparently Sublime's default (and only) behavior is to reverse-indent code lines, but leave html lines flush. So when I'm editing a PHP/HTML document, my wrapped lines will reverse-indent about half the time, depending on whether I'm in an tag or in a fragment at that line break.
The effect on my code is something like this:
<!-- Wrapped HTML doesn't reverse indent -->
<a href='long_link_that_causes_lines_to_wrap' other_attribute='
jquery_thing_that_makes_lines_wrap'>something</a>
...
<!-- Wrapped PHP snippets do reverse indent -->
<? echo date('M jS', strtotime('some_interpolated_formatting_string',
$some_variable_expression)); ?>

Sublime uses JSON files to store your preferences. The default file lists the settings that it uses by default, and you can override them by adding them to your user file.
The preference that controls hanging indent is word_wrap:
// Disables horizontal scrolling if enabled.
// May be set to true, false, or "auto", where it will be disabled for
// source code, and otherwise enabled.
"word_wrap": "auto",
As shown above, the default value is auto which only wraps lines that are not considered source code. To get hanging indent on all lines in a file, you need to set it to true in your user preferences file:
"word_wrap": true,

Related

Replacing stuff of HTML using regex

I am editing a couple of hundred HTML files and I have to replace all the stuff manually, so I was wondering whether it could be done using regex.I don't think it is possible, but it might be, so please help me out.
Okay, so for example, I have many <p> tags in a file, each with a different class. eg:
<p class="class1">stuff here</p>
<p class="class2">more stuff here</p>
I wanted to replace the "stuff here" and "more stuff here" with something, for example
<p class="class1">[content]</p>
<p class="class2">[content]</p> .
I wanted to know if that is possible.
I'm using notepad++.
P.S. I'm new to regex.
I think notepad++ is great for stuff like this. Open up Find/Replace, and check the regular expressions box in the dialog's Search Mode section.
In the "Find what" field, try this:
\<p\ class\=(.*)\>(.*)\<\/p\>
and in "Replace with":
\<p\ class\=\1\>[content]\<\/p\>
the \1 here will take whatever (found by (.*)) between the class= and the angle bracket > which ends the tag, and replace it with itself, which essentially results in ignoring the class name, rather than having to specify. the second (.*) catches the current content inside the paragraph tag, which is what you want to replace. So where I wrote [content] in the "Replace with" block, that's where you'd put your new content. This does limit you to content that you can paste into the notepad++ find/replace dialog, but I think it has a pretty huge limit.
If I'm remembering that text field's limitations incorrectly, another thing you could do is just adjust my "Replace with" text to just replace the old text with some newlines:
\<p\ class\=\1\>\n\n\<\/p\>
This will delete the old text and leave a clear line where it once was, making it easy to paste whatever you want into the normal editor pane.
The first way is probably better, if your new content will fit the Replace With field, because this regex works once per line. And you can click "Replace" a couple times, and if it's working, clicking "Replace all" will iterate through every <p> element in the file.
Note: this solution assumes that your <p> tags open and close within one line, as you typed them your question description. If they break lines, you're going to want to enable . matches newline in the Replace dialog, and... you need trickier (more precise) syntax than (.*) to catch your class name and content-to-be-replaced. Let me know if this is the the case, and I'll fiddle with it and see if I can help more. The (.*) needs to change to (.*?) or something; the search needs to get more greedy, because if . matches newline, then .* matches any and every possible character infinite times, i.e., the whole document.

After "a{display text}", then pasting the url, how can I get the cursor to go after the close </a>? Like $0 in a Sublime autocomplete

I'm using Emmet in Sublime Text 3.
After executing a{display text}, you get
display text
What I'm trying to do is get the cursor to jump to after the close </a>, after I've pasted in the url. I'm trying to simulate Sublime's autocomplete $0 behavior, like
display text$0
I am looking through snippets.json, but I'm not getting it. The only "a" entry is in the "abbreviations" object, and contains only the open tag:
"a": "<a href=\"\">",
I've not edited any Emmet tags before, and I thought this might be a good first one to try.
Any ideas on how this might be possible?
There's a built-in Emmet setting that does this for all tags:
This is in C:\Users\jeffy\AppData\Roaming\Sublime Text 3\Packages\Emmet\Emmet.sublime-settings
// If set to `true`, Emmet will automatically insert final tabstop
// at the end of expanded abbreviation
"insert_final_tabstop": false
I duplicated it to C:\Users\jeffy\AppData\Roaming\Sublime Text 3\Packages\User\Emmet.sublime-settings
and changed it to true. It does exactly as I want. Well, it still goes to the display text, even if there already is display text. Then it goes to the end. But close enough!

Can I wrap a text selection in a tag in phpstorm?

Suppose I have a text:
This is my text!
How beautiful it is!
And I want to wrap each line within a p-tag, is there an easier way than to navigate to each line and add them manually and have them close semi-automatically?
I want them to look like this:
<p>This is my text!</p>
<p>How beautiful it is!</p>
while having to do as less as possible.
Select your lines
Code | Surround With...
For Windows/Linux: Ctrl + Alt + T
For MacOS: Cmd + Alt + T
Choose "Emmet"
Type p* -- this will surround each line with <p> tag
NOTE: Empty lines will be wrapped as well so it is better remove them in advance.
Similar/related case.
P.S.
In current versions of IDE the dedicated "Surround with Emmet" action is available which allows you to bring that popup window in one key stroke instead of having going trough via intermediate Surround with... popup menu first.
That action has no shortcut defined by default, but you can easily change that and assign any desired shortcut in Settings/Preferences | Keymap -- just look for Other | Surround with Emmet action (hint: use search box to speed up your search).

Sublime Text 2 - Problems with HTML automatic indentation

Every time I type an opening html tag (like <div>) then press the Enter key, the cursor automatically inserts an indention on the next line. However I don't want it to be indented since I still have to write the closing tag (actually I press the enter twice and write the closing tag in the third line so I can have an empty line in between). Now I have to press the back button to align the cursor with the opening tag.
I am aware of Sublime Text 2's autocomplete like when you type '<' and Ctrl + Space, a list
of available elements would appear. And when you select one item from the list, the editor would
provide you of both the opening and the closing tag. However, I'm not used to that kind of typing.
So is there a way to turn off this annoying feature of Sublime Text 2
You can disable auto-indentation by setting auto_indent to false.
In order to do this for the HTML syntax only, go to Preferences/Settings – More/Syntax Specific – User and insert the following contents:
{
"auto_indent": false
}
This will make the cursor to jump back at column 0 after hitting return.
To make it stay at the column of the opening tag, re-enable auto_indent and tweak the indentation settings in Packages/HTML/Miscellaneous.tmPreferences. If you aren’t into regular expressions, try to get rid of this file completely.
You can also just type the closing </div> tag and sublime text will automatically un-indent it for you.

Flex4.6 StyleableTextField ignores <br> and <p> tags

I've got a StyleableTextField in my mobile project, which gets filled with html text using the .htmlText property.
The tag is working fine for me, but simple line breaks or paragraphs are simply ignored. What can I do about that?
Basically, the simplest HTML will just be displayed as a single line:
textField.htmlText = "<p>this should be the first line</p><p>this the second one</p>";
Again, the output is a single line.
The Flex 3 doc states that those tags are definitely supported, so I reckon they simply removed it in the newer versions (which is kinda ridiculous!).
I don't want to use the stagewebview, so what other ways to I have to properly format HTML using the StyleableTextField, or is there a simple replacement for the aforementioned tags?
Thank you very much guys!
Make sure that multiline is set to true, otherwise it will treat it as a single line of text, effectively ignoring the formatting.