Sublime text2 的几个小技巧和资料汇总

转载自这里  转载自这里   转载自这里

Sublime text2是一个编辑神器,这是毋容置疑的。从vim转到sublime text2后,我感觉更为轻松了。当然,我也喜欢vim。所以,我喜欢把我的sublime text2设置成vim模式。

这样,就可以结合vim和sublime text2的优点了。本文,我做一些简单的总结,希望对大家有所帮助。

虽然,现在已经有sublime text3了,但是还是喜欢 sublime text2。:-) 本文是介绍sublime text2 。

环境: mac + sublime text2

  1. 安装 Package Control 插件
    PC插件是我们安装其他插件的必要条件,安装也特别简单。
    [plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. command+`    

    然后输入  

    [plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'  


    回车即可

    如何调用 Package Control ? 
    command + shift +p, 然后输入  package ,选中 Package Control: install package 即可

  2. default user settings
    如下是我的default user settings
    [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. {  
    2.     "auto_complete"true,  
    3.     "bold_folder_labels"true,  
    4.     "caret_style""phase",  
    5.     "default_line_ending""unix",  
    6.     "ensure_newline_at_eof_on_save"true,  
    7.     "font_size": 14.0,  
    8.     "highlight_line"true,  
    9.         "ignored_packages": [],  
    10.     "rulers":  
    11.     [  
    12.         100  
    13.     ],  
    14.     "scroll_past_end"true,  
    15.     "tab_size": 2,  
    16.     "translate_tabs_to_spaces"true,  
    17.     "trim_trailing_white_space_on_save"true,  
    18.     "vintage_ctrl_keys"true,  
    19.     "vintage_start_in_command_mode"true  
    20. }  

    [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. "ignored_packages": [],  
    ST2 默认情况下,会disable掉 vim 的功能支持,如果习惯用vim的用户

  3. 置自己的Project
    我们在用sublime text2 打开一个文件夹后,可以将该文件夹保存成一个Project。这样的好处是,我们可以往一个Project下增加不同的目录,并且,可以设置名称。
    还可以通过快捷键切换不同的Project.

    具体的操作是: Project -> save project 

    参考文件是
    [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. {  
    2.     "folders":  
    3.     [  
    4.         {  
    5.             "path""src",  
    6.             "folder_exclude_patterns": ["backup"]  
    7.         },  
    8.         {  
    9.             "path""docs",  
    10.             "name""Documentation",  
    11.             "file_exclude_patterns": ["*.css"]  
    12.         }  
    13.     ],  
    14.     "settings":  
    15.     {  
    16.         "tab_size": 2  
    17.     },  
    18.     "build_systems":  
    19.     [  
    20.         {  
    21.             "name""List",  
    22.             "cmd": ["ls"]  
    23.         }  
    24.     ]  
    25. }  



  4. ST2的插件
    1. All autocomplete
      自动补全插件,先装着吧。 可以结合后面的ctags 做补全。

    2. Gist 
      在ST2中,集成github的gist插件。有了它,我们可以在ST2中创建,修改,删除和使用gist代码。
      Gist的配置
      Applications -> Personal Access Tokens -> generate a token

      Use the token to Gist setting file like this:
      [plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. {  
      2.   "token": "614f564034a3400a7d4ad5bb5b0d18f2c3c5d889"  
      3. }  

      command+shift+p: input gist: open xxx 

    3. PlainTasks
      简单的todo-list task管理工具

    4. markdown preview
      在ST中,查看markdown 文档,非常的方便

    5. Fetch 可以从远程 fetch 代码到本地


    6. snippet 系列插件: jquery mobile snippet  等


    7. AdvanceNewFile
      提高我们创建和修改文件名称的快捷操作,还是有其的功能

    8. Pretty JSON
      格式化我们的json代码,有时候特别有用

    9. Bracket​Highlighter
      括号高亮,看代码的利器啊

    10. Prefixr
      写跨平台的css的插件,能自动生成。绑定的快捷键是 super+alt+x


    11. ctags
      必装插件,用于代码之间的跳转

      mac自带的 ctags 不行,换成 brew install ctags 的方法

      [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. sudo rm /usr/bin/ctags  
      2. sudo ln -s /usr/local/Cellar/ctags/5.8/bin/ctags /usr/bin/ctags  

      如下的code可以为我们的Gem tag,在阅读代码的时候特别有用

      1. 在项目下,新建一个ctags_for_ruby 的文件,code 如下

      [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. #!/usr/bin/env ruby  
      2. system "find . -name '*.rb' | ctags -f .tags -L -"  
      3.   
      4. if File.exist? './Gemfile'  
      5.   require 'bundler'  
      6.   paths = Bundler.load.specs.map(&:full_gem_path).join(' ')  
      7.   system "ctags -R -f .gemtags #{paths}"  
      8. end  
      2. 运行 ctags_for_ruby
      3. 修改ctags的配置文件为
      [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. {  
      2.     "debug"           :  false,  
      3.     "autocomplete"false,  
      4.     "command"   :  "ctags_for_ruby",  
      5.     "filters"         :  {  
      6.         "source.python": {"type":"^i$"}  
      7.     },  
      8.     "definition_filters": {  
      9.         "source.php": {"type":"^v$"}  
      10.     },  
      11.     "definition_current_first"true,  
      12.     "show_context_menus"true,  
      13.     "extra_tag_paths" :  [ [["source.python""windows"], "C:\\Python27\\Lib\\tags"]],  
      14.     "extra_tag_files" : [".gemtags"".tags"]  
      15. }  


    12. Gem Browser
      可以方便的打开一个Gem文件目录, 不同的rvm 可以参考 https://github.com/fblee/sublime-gem-browser-gemset
      使用方法: command + shift + p 输入 List Gems 

      https://github.com/NaN1488/sublime-gem-browser

        cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/
        git clone https://github.com/NaN1488/sublime-gem-browser.git
    13. zenCoding
      提高开发速度的神器,少写很多代码,只是有态度的内容需要记了

    14. SideBarEnhancements
      增强我们的边栏功能




  5. 打造自己的Rails编辑器
    1. Rails Related File
      快速定位到我们需要的相关的Rails 文件,比如通过controller 寻找 helper/views 等
      命令是 command + shift+ O

    2. 使用RubyTest插件测试我们的ruby
      https://github.com/maltize/sublime-text-2-ruby-tests#note
      几处需要修改的配置
      [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. "check_for_rbenv"true,  
      2. "check_for_rvm"true,  
      3. "run_rspec_command""bundle exec rspec {relative_path}",  
      4. "run_single_rspec_command""bundle exec rspec {relative_path} -l{line_number}",  
      5. "ruby_use_scratch" : true,  
      6. "save_on_run"true,  

      [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. ruby_use_scratch  
      设置成true 后,ST2会在一个新的tab输出rspec的信息


    3. simple rails nav
      Rails 文件的更快的跳转

      安装后,需要自己配置快捷键,如下可供参考

      [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
      1. // simple navigate rails  
      2. "keys": ["super+shift+m"], "command""list_rails_models" },  
      3. "keys": ["super+shift+c"], "command""list_rails_controllers" },  
      4. "keys": ["super+shift+v"], "command""list_rails_views" },  
      5. "keys": ["super+shift+h"], "command""list_rails_helpers" },  
      6. "keys": ["super+shift+x"], "command""list_rails_fixtures" },  
      7. "keys": ["super+shift+t"], "command""list_rails_tests" },  
      8. "keys": ["super+shift+i"], "command""list_rails_javascripts" },  
      9. "keys": ["super+shift+y"], "command""list_rails_stylesheets" },  
      10. "keys": [" ""m"], "command""list_rails_models""context": [{"key""setting.command_mode"}] },  
      11. "keys": [" ""c"], "command""list_rails_controllers""context": [{"key""setting.command_mode"}] },  
      12. "keys": [" ""v"], "command""list_rails_views""context": [{"key""setting.command_mode"}] },  
      13. "keys": [" ""h"], "command""list_rails_helpers""context": [{"key""setting.command_mode"}] },  
      14. "keys": [" ""x"], "command""list_rails_fixtures""context": [{"key""setting.command_mode"}] },  
      15. "keys": [" ""t"], "command""list_rails_tests""context": [{"key""setting.command_mode"}] },  
      16. "keys": [" ""i"], "command""list_rails_javascripts""context": [{"key""setting.command_mode"}] },  
      17. "keys": [" ""y"], "command""list_rails_stylesheets""context": [{"key""setting.command_mode"}] }  
      https://github.com/noklesta/SublimeRailsNav  



  6. 常用的快捷键和命令
    光标操作我们代码
    [ruby]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. $ 移动到 行首  
    2. 0 移动到行尾  
    3. ^ 移动到第一个非空字符  
    4. j 下  
    5. k 上  
    6. h 左  
    7. l 右边  
    8. v+j... 选中  

    移动10行,使用 10+j

  7. 我的快捷键设置分享
    [javascript]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
    1. [  
    2.     {  
    3.         "keys": ["super+o"],  
    4.         "command""side_bar_open_in_browser",  
    5.         "args":{ "paths":[], "type":"production" }  
    6.     },  
    7.     { "keys": ["alt+r"], "command""side_bar_rename" },  
    8.     { "keys": ["alt+n"], "command""advanced_new_file"},  
    9.   { "keys": ["super+shift+up"], "command""select_lines""args": {"forward"false} },  
    10.   { "keys": ["super+shift+down"], "command""select_lines""args": {"forward"true} },  
    11.     {"command""navigate_to_definition""keys": ["alt+command+down"] },  
    12.     {"command""jump_back""keys": ["alt+command+up"] },  
    13.   {"command""rebuild_tags""keys": ["alt+command+r"] },  
    14.   {"keys": ["ctrl+shift+a"], "command""alignment"},  
    15.   
    16.     {  
    17.         "keys": ["super+alt+left"],  
    18.         "command""set_layout",  
    19.         "args":  
    20.         {  
    21.             "cols": [0.0, 0.33, 1.0],  
    22.             "rows": [0.0, 1.0],  
    23.             "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]  
    24.         }  
    25.     },  
    26.   
    27.     {  
    28.         "keys": ["super+alt+right"],  
    29.         "command""set_layout",  
    30.         "args":  
    31.         {  
    32.             "cols": [0.0, 0.66, 1.0],  
    33.             "rows": [0.0, 1.0],  
    34.             "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]  
    35.         }  
    36.     },  
    37.   
    38.     { "keys": ["alt+1"], "command""move_to_group""args": { "group": 0 } },  
    39.     { "keys": ["alt+2"], "command""move_to_group""args": { "group": 1 } },  
    40.     { "keys": ["alt+3"], "command""move_to_group""args": { "group": 2 } },  
    41.     { "keys": ["alt+4"], "command""move_to_group""args": { "group": 3 } },  
    42.   
    43.     //simple special file nav: https://github.com/fblee/rails_special_file_nav  
    44.     { "keys": ["super+ctrl+g"],  "command""gemfile_navigation"},  
    45.     { "keys": ["super+ctrl+r"],  "command""rakefile_navigation"},  
    46.   
    47.     // simple navigate rails  
    48.     { "keys": ["super+shift+m"], "command""list_rails_models" },  
    49.     { "keys": ["super+shift+c"], "command""list_rails_controllers" },  
    50.     { "keys": ["super+shift+v"], "command""list_rails_views" },  
    51.     { "keys": ["super+shift+h"], "command""list_rails_helpers" },  
    52.     { "keys": ["super+shift+x"], "command""list_rails_fixtures" },  
    53.     { "keys": ["super+shift+t"], "command""list_rails_tests" },  
    54.     { "keys": ["super+shift+i"], "command""list_rails_javascripts" },  
    55.     { "keys": ["super+shift+y"], "command""list_rails_stylesheets" },  
    56.     { "keys": [" ""m"], "command""list_rails_models""context": [{"key""setting.command_mode"}] },  
    57.     { "keys": [" ""c"], "command""list_rails_controllers""context": [{"key""setting.command_mode"}] },  
    58.     { "keys": [" ""v"], "command""list_rails_views""context": [{"key""setting.command_mode"}] },  
    59.     { "keys": [" ""h"], "command""list_rails_helpers""context": [{"key""setting.command_mode"}] },  
    60.     { "keys": [" ""x"], "command""list_rails_fixtures""context": [{"key""setting.command_mode"}] },  
    61.     { "keys": [" ""t"], "command""list_rails_tests""context": [{"key""setting.command_mode"}] },  
    62.     { "keys": [" ""i"], "command""list_rails_javascripts""context": [{"key""setting.command_mode"}] },  
    63.     { "keys": [" ""y"], "command""list_rails_stylesheets""context": [{"key""setting.command_mode"}] }  
    64.   
    65.     //rubytest  
    66.     // {"command": "run_single_rspec_command", "keys": ["super+s", "super+shift+r"]}  
    67. ]  





参考资料

视频: http://net.tutsplus.com/articles/news/perfect-workflow-in-sublime-text-free-course/

ctags 和 auto complete 结合: https://gist.github.com/BlackMac/1825401

https://thunderboltlabs.com/blog/2013/11/19/efficiency-with-sublime-text-and-ruby/

http://www.cnblogs.com/xiaowu/archive/2012/08/27/2658534.html

http://blog.alainmeier.com/post/27255145114/some-things-beginners-might-not-know-about-sublime-text



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值