Sublime text2是一个编辑神器,这是毋容置疑的。从vim转到sublime text2后,我感觉更为轻松了。当然,我也喜欢vim。所以,我喜欢把我的sublime text2设置成vim模式。
这样,就可以结合vim和sublime text2的优点了。本文,我做一些简单的总结,希望对大家有所帮助。
虽然,现在已经有sublime text3了,但是还是喜欢 sublime text2。:-) 本文是介绍sublime text2 。
环境: mac + sublime text2
command+`
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'
{
"auto_complete": true,
"bold_folder_labels": true,
"caret_style": "phase",
"default_line_ending": "unix",
"ensure_newline_at_eof_on_save": true,
"font_size": 14.0,
"highlight_line": true,
"ignored_packages": [],
"rulers":
[
100
],
"scroll_past_end": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"vintage_ctrl_keys": true,
"vintage_start_in_command_mode": true
}
"ignored_packages": [],
ST2 默认情况下,会disable掉 vim 的功能支持,如果习惯用vim的用户{
"folders":
[
{
"path": "src",
"folder_exclude_patterns": ["backup"]
},
{
"path": "docs",
"name": "Documentation",
"file_exclude_patterns": ["*.css"]
}
],
"settings":
{
"tab_size": 2
},
"build_systems":
[
{
"name": "List",
"cmd": ["ls"]
}
]
}
{
"token": "614f564034a3400a7d4ad5bb5b0d18f2c3c5d889"
}
mac自带的 ctags 不行,换成 brew install ctags 的方法
sudo rm /usr/bin/ctags
sudo ln -s /usr/local/Cellar/ctags/5.8/bin/ctags /usr/bin/ctags
如下的code可以为我们的Gem tag,在阅读代码的时候特别有用
1. 在项目下,新建一个ctags_for_ruby 的文件,code 如下
#!/usr/bin/env ruby
system "find . -name '*.rb' | ctags -f .tags -L -"
if File.exist? './Gemfile'
require 'bundler'
paths = Bundler.load.specs.map(&:full_gem_path).join(' ')
system "ctags -R -f .gemtags #{paths}"
end
{
"debug" : false,
"autocomplete": false,
"command" : "ctags_for_ruby",
"filters" : {
"source.python": {"type":"^i$"}
},
"definition_filters": {
"source.php": {"type":"^v$"}
},
"definition_current_first": true,
"show_context_menus": true,
"extra_tag_paths" : [ [["source.python", "windows"], "C:\\Python27\\Lib\\tags"]],
"extra_tag_files" : [".gemtags", ".tags"]
}
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
zenCoding
提高开发速度的神器,少写很多代码,只是有态度的内容需要记了
{"keys": [" ", "c", "m"], "command": "shell_prompt"}
"check_for_rbenv": true,
"check_for_rvm": true,
"run_rspec_command": "bundle exec rspec {relative_path}",
"run_single_rspec_command": "bundle exec rspec {relative_path} -l{line_number}",
"ruby_use_scratch" : true,
"save_on_run": true,
ruby_use_scratch
设置成true 后,ST2会在一个新的tab输出rspec的信息安装后,需要自己配置快捷键,如下可供参考
// simple navigate rails
{ "keys": ["super+shift+m"], "command": "list_rails_models" },
{ "keys": ["super+shift+c"], "command": "list_rails_controllers" },
{ "keys": ["super+shift+v"], "command": "list_rails_views" },
{ "keys": ["super+shift+h"], "command": "list_rails_helpers" },
{ "keys": ["super+shift+x"], "command": "list_rails_fixtures" },
{ "keys": ["super+shift+t"], "command": "list_rails_tests" },
{ "keys": ["super+shift+i"], "command": "list_rails_javascripts" },
{ "keys": ["super+shift+y"], "command": "list_rails_stylesheets" },
{ "keys": [" ", "m"], "command": "list_rails_models", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "c"], "command": "list_rails_controllers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "v"], "command": "list_rails_views", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "h"], "command": "list_rails_helpers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "x"], "command": "list_rails_fixtures", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "t"], "command": "list_rails_tests", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "i"], "command": "list_rails_javascripts", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "y"], "command": "list_rails_stylesheets", "context": [{"key": "setting.command_mode"}] }
$ 移动到 行首
0 移动到行尾
^ 移动到第一个非空字符
j 下
k 上
h 左
l 右边
v+j... 选中
[
{
"keys": ["super+o"],
"command": "side_bar_open_in_browser",
"args":{ "paths":[], "type":"production" }
},
{ "keys": ["alt+r"], "command": "side_bar_rename" },
{ "keys": ["alt+n"], "command": "advanced_new_file"},
{ "keys": ["super+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["super+shift+down"], "command": "select_lines", "args": {"forward": true} },
{"command": "navigate_to_definition", "keys": ["alt+command+down"] },
{"command": "jump_back", "keys": ["alt+command+up"] },
{"command": "rebuild_tags", "keys": ["alt+command+r"] },
{"keys": ["ctrl+shift+a"], "command": "alignment"},
{
"keys": ["super+alt+left"],
"command": "set_layout",
"args":
{
"cols": [0.0, 0.33, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}
},
{
"keys": ["super+alt+right"],
"command": "set_layout",
"args":
{
"cols": [0.0, 0.66, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}
},
{ "keys": ["alt+1"], "command": "move_to_group", "args": { "group": 0 } },
{ "keys": ["alt+2"], "command": "move_to_group", "args": { "group": 1 } },
{ "keys": ["alt+3"], "command": "move_to_group", "args": { "group": 2 } },
{ "keys": ["alt+4"], "command": "move_to_group", "args": { "group": 3 } },
//simple special file nav: https://github.com/fblee/rails_special_file_nav
{ "keys": ["super+ctrl+g"], "command": "gemfile_navigation"},
{ "keys": ["super+ctrl+r"], "command": "rakefile_navigation"},
// simple navigate rails
{ "keys": ["super+shift+m"], "command": "list_rails_models" },
{ "keys": ["super+shift+c"], "command": "list_rails_controllers" },
{ "keys": ["super+shift+v"], "command": "list_rails_views" },
{ "keys": ["super+shift+h"], "command": "list_rails_helpers" },
{ "keys": ["super+shift+x"], "command": "list_rails_fixtures" },
{ "keys": ["super+shift+t"], "command": "list_rails_tests" },
{ "keys": ["super+shift+i"], "command": "list_rails_javascripts" },
{ "keys": ["super+shift+y"], "command": "list_rails_stylesheets" },
{ "keys": [" ", "m"], "command": "list_rails_models", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "c"], "command": "list_rails_controllers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "v"], "command": "list_rails_views", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "h"], "command": "list_rails_helpers", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "x"], "command": "list_rails_fixtures", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "t"], "command": "list_rails_tests", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "i"], "command": "list_rails_javascripts", "context": [{"key": "setting.command_mode"}] },
{ "keys": [" ", "y"], "command": "list_rails_stylesheets", "context": [{"key": "setting.command_mode"}] }
//rubytest
// {"command": "run_single_rspec_command", "keys": ["super+s", "super+shift+r"]}
]
参考资料
视频: 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