开发工具 TextMate 2 总结笔记 (简)

xiaolai · 2012年10月08日 · 最后由 cloudzine 回复于 2015年04月21日 · 14343 次阅读

http://lixiaolai.com/alpha/notes/TextMate2.html

#官方下载链接 https://github.com/textmate/textmate/downloads

#Bundle 目录 官方博客上说,TM2 的 Bundle 目录是

~/Library/Application Support/Avian/Pristine Copy/Bundles/

令人困惑的是,以下目录也可用

~/Library/Application Support/Avian/Bundles/

TextMate 默认带的那些 Bundles 都放在以下目录中:

~/Library/Application Support/TextMate/Managed/Bundles

可在 TextMate 中直接安装的,与 Rails 相关的 Bundles:

  • RSpec
  • Ruby
  • Ruby Haml
  • Ruby on Rails
  • Ruby Sass
  • Ruby Shoulda

需要下载安装的 Bundles:

#全局设置文件 TM2 可以自定一个全局设置,保存在~/.tm_properties 文件中。可参考:https://gist.github.com/1478685。我的如下:

# Settings
fontName             = "Menlo"
fontSize             = 15
softTabs             = true
tabSize              = 2
projectDirectory     = "$CWD"
windowTitle          = "$TM_DIRECTORY/$TM_DISPLAYNAME - ${CWD/^.*\///}"
TM_ORGANIZATION_NAME = 'xiaolai'

# Variables
TM_GIT           = "usr/local/bin/git"
TM_RUBY          = "$HOME/.rvm/bin/rvm-auto-ruby" #for rvm swithing rubies

[ .git/COMMIT_EDITMSG ]
softWrap         = true
spellChecking    = true
spellingLanguage = 'en'

[ text ]
softWrap         = true
spellChecking    = true

[ *.{icns,ico,jpg,jpeg,m4v,nib,pdf,png,psd,pyc,rtf,tif,tiff,xib} ]
binary           = true

[ "{README,INSTALL,LICENSE,TODO}" ]
fileType         = "text.plain"

[ "{markdown,md}" ]
fileType         = "Markdown"

#让 TextMate 使用正确的 Ruby 版本

~/.tm_properties文件中添加:

TM_RUBY = "$HOME/.rvm/bin/rvm-auto-ruby"

更多参见:https://rvm.io//integration/textmate/

在 Terminal 用rvm list命令查看当前使用的 Ruby 版本,而后用 TexMate 创建一个.rb文件,输入以下内容而后按 ⌘b,看看输出结果是不是与当前的 ruby 版本一致:

puts RUBY_DESCRIPTION

#随时使用⌃h 查看文档

尽管很多教程都推荐在~/.gemrc 里面添加如下内容:

install --no-doc --no-ri
update --no-doc --no-ri

可新手最好不要这么做。如果你已经这么做了,那就 1) 清除~/.gemrc文件中的这两行;2) 运行gem install rdoc-data重新加载文档。以后你就可以随时用⌃h 查看文档,查询函数、类的方法属性之类……

#安装 Theme

#Macro TM 只能记录一个 Macro,但也足够了,因为我只需要一个:

⌥⌘m、空格、空格、←、⌥⌘m

如此这般之后,以后就可以用 ⇧⌘m 在当前光标之前、之后各添加一个空格。比如这样:{ | }

关于 Macro,这里有个例子可以看:Macros for working with Markdown lists in TextMate

#视频教程

http://macromates.com/screencasts

这个视频必看:Working with Comments。另外,在这个视频里可以看到如何在 TM 中管理自己的 TODO——实在是太方便了。

另外一个入门必看的是:Html text Transformation

#高级开关

http://manual.macromates.com/en/expert_preferences.html

说实话,基本上没什么大用处。

#1 分钟体验快速输入

##输入 html tags

按⇧⌃⌥h,将当前文本的属性设置为html

  • ⇧⌃w, 而后直接输入 html tag,比如h1,而后再按⇥,光标会挪到<h1></h1>之间

  • Zen-Coding: 输入div#content.left-pane>ul>li.item-list*5而后按⌘e,这段代码会展开为:

<div id="content" class="left-pane">
  <ul>
    <li class="item-list"></li>
    <li class="item-list"></li>
    <li class="item-list"></li>
    <li class="item-list"></li>
    <li class="item-list"></li>
  </ul>
</div>

同时,光标会在<li class="item-list"></li>之间,而接下来⇥或 ⇧⇥将使光标在<li></li>之间跨越。

  • 输入form之后按⇥,将被展开为
<form action="TexMate2_submit" method="get" accept-charset="utf-8">


  <p><input type="submit" value="Continue &rarr;"></p>
</form>
  • 在输入任何字符(英文)之后,按⎋,将被替换为当前文本中已经出现过的以此字母(或字母组合)为开头的词汇

  • ⌥⌘.将会补全当前尚未关闭的 tag。

  • 将当前文字注释掉,用⌘/。(需要安装这个 Bundle: Source)

##编辑多处文字

  • 选中一段文字(字、词、句、块)之后,按⌘再选其它文字,而后可同时修改这些文字。(安装 CTags 之后,这个快捷键会失灵……)
  • 选中多行文字,而后按一下⌥,光标将延伸到每一行,而后输入的内容将在每一行出现。用触摸板点击任何其它地方,将结束这种编辑模式。

#cheatsheet

#与 Finder/Terminal 的交互

##从命令行中找到一个目录并用 TextMate 打开该目录

find ~/clients -type d -name 'goodie69' -exec mate {} \;

via: http://www.givegoodweb.com/post/86/use-terminal-to-find-and-create-a-textmate-project

将以下代码保存到~/.bash_profile中:

# find in $directory where $name
fmate(){
  find $1 -type d -name $2 -exec mate {} \;
}

##在 TextMate 中打开 Terminal 并 cd 至当前文件所在目录

快捷键为:⇧⌃o

##在 Finder 工具栏上添加一个“Open in TextMate”按钮

http://henrik.nyh.se/2007/10/open-in-textmate-from-leopard-finder/

{% img center http://henrik.nyh.se/uploads/finder-leopard-tm.png %}

#在 Drawer 中显示某些特定的隐含文件

Preferences > Project > Include files matching,改为:

{*,.tm_properties,.htaccess,.gitignore,.rvmrc}

更多参见: https://gist.github.com/1028882

在同一对话框中,可以将"Command output"改为Right of text view——这对使用宽屏的人有很大帮助。

#将当前打开的所有文件保存到一个 Project 中

TextMate: Make Project from Open Files

  • 居然在这里找到另外一个好玩的东西:appscript

#推荐教程

#Mac-OS-X terminal cheat-sheet

http://software.clapper.org/cheat-sheets/mac-os-x.html

匿名 #2 2012年12月07日

从 TextMate 升级到 2 后,有些使用 TM 写 Octopress 输入中文出现了退出。

李老师之前不是用 sublime text 吗

#3 楼 @ted 用过一阵子。后来还是退回 TextMate2 了

TextMate2 能自动提示吗,用惯了 sublime 的自动提示。

sublime text 2 与 textmate 一直在互相用。谢谢 mark

请问这个 textmate 2.0 里面的 Ruby on Rails.bundle 是坏掉的吗?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号