I came from the Windows TextMate clone e-texteditor. And in that app, and set to Ruby on Rails bundle while in an .html.erb
document, if I was to type Ctrl-Alt-W (equivalent to Ctrl-Shift-W in TextMate), then I get
with the letter "p" in the first pointed brackets highlighted where I can type any text and the other closing brackets' "p" will change accordingly. All is well in both TextMate and in e-texteditor so far. But in e-texteditor, if I then press Tab, the cursor will be moved to the content of these HTML tags like this:
|
where |
represents the cursor. Now I know that Ctrl-Shift-W is supposed to wrap selected text in TextMate, and e-texteditor does that, too! But I find being able to make a pair of HTML tags and tab inside instead of arrow-key myself back in very convenient.
Perhaps there is another shortcut for this?
Just in case I am not being crystal clear already: Ctrl-Shift-W (or another shortcut), when pressed, first generates
with the first 'p' highlighted ready to be changed. Changed or not, when Tab is then pressed, the cursor should go in between these opening and closing HTML tags.
Answer
EDIT
Something was bugging me with your question: I didn't remember having that problem at all but I somehow forgot most of what I once knew about TextMate (switched to Vim a year ago). I just re-licensed TextMate to play around with TM2 so here is your answer:
You are using the "wrong" shortcut.
CtrlShiftW is for wrapping the currently selected text with opening and closing tags.
Since you hit this shortcut without a selection you end up with an empty tag. Because it's designed to work with some pre-existing content it's quite logical that it doesn't provide the ability to edit said content further.
The typical use case is when you paste some raw text from a brief and go through it to add proper HTML formatting.
This shortcut inserting an empty HTML tag pair is something of a mirage. Sure it does that but it's a side effect of not using it properly.
The correct shortcut is Ctrl< which is for inserting opening and closing tags optionally using the current word.
You can use it in two ways:
If you have whitespace on the left of the caret, hit Ctrl< to insert
with the first
p
selected. You can either changep
to something likeh1
and have it mirrored to the closing tag or hit Tab to move the caret between the tags, like that:
.|
Which, I think, is exactly what you want and, actually, what I've always done. Hence my discomfort with your question.
If your caret is positioned just after a word, say
span
, hit Ctrl< to replacespan
withwith the first
span
selected. You have now the exact same possibilities as with the first method.
END EDIT
My TextMate days are gone now so this solution is probably not the best one but it's very easy to put in practice.
Simply create a snippet with the letter t
as trigger and
<${1:tag}>$0$1>
as content.
When it's done you only have to type t
then your content.
Obviously, as it is there is a rather important drawback: if you add attributes they will be mirrored to the end tag.
This can be mitigated by adding an extra tab stop:
<${1:tag}${2: }>$0$1>
No comments:
Post a Comment