在 TextMate 中标记时添加常用代码块的最佳方法是什么?
警告:我对编码以及 TextMate 都比较陌生,所以如果有一个明显的答案,我很抱歉这里失踪了。
我做了很多 HTML/CSS 标记,有一些我经常使用的模式,例如表单、导航菜单等。我想要的是一种存储这些模式并在需要时快速插入它们的方法。
有没有办法使用 TextMate 来做到这一点?
Caveat: I'm relatively new to coding as well as TextMate, so apologies if there is an obvious answer I'm missing here.
I do a lot of HTML/CSS markup, there are certain patterns that I use a lot, for example, forms, navigation menus etc. What I would like is a way to store those patterns and insert them quickly when I need them.
Is there a way to do this using TextMate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 TextMate 中使用 Snippets 轻松完成此操作。 只需在捆绑编辑器中添加一个新的代码片段,并设置您想要的触发方式。 您可以设置快捷键,或者在特定单词/模式后按
Tab
时弹出该快捷键。您可以用它们做很多事情 - 在您的情况下,在代码片段中设置所谓的“占位符”可能非常有用,这些占位符是每次都会更改的部分(例如表单中的字段名称) )。 然后,一旦插入片段,您就可以点击
Tab
在这些片段之间移动。You can do this very easily in TextMate using Snippets. Just add a new snippet in the bundle editor, and set up how you want to trigger it. You can set a key shortcut, or have it pop up when you hit
Tab
after a certain word/pattern.There are many things you can do with them—in your case, it would probably be very useful to set so-called "placeholders" in your snippets, which are the parts that change every time (e.g. the names of the fields in the form). Then, as soon as you insert the snippet, you can hit
Tab
to move between these.如前所述,前面的片段就是您正在寻找的内容。
作为参考,请看这里:
http://manual.macromates.com/en/snippets
http://screenflicker.com/mike/code/div-snippets/
As mentioned prior snippets are what you are looking for.
For reference look here:
http://manual.macromates.com/en/snippets
http://screenflicker.com/mike/code/div-snippets/
除了上面提供的链接之外,我想您会发现此截屏很有用。 它提供了 TextMate 的 HTML 包已经提供的一些工具的运行。
虽然可能有点偏离主题,但仍然值得一看。
Along with the links provided above, I think you'll find this screencast useful. It gives a run through of some of the tools TextMate's HTML bundle already provides.
It's probably slightly off-topic though, but worth a look nonetheless.