我注意到 Vim 需要很长时间才能打开 Ruby 和 ERB(嵌入式 Ruby)文件。我分析了我的启动时间和这些有趣的行(如果您想查看完整的配置文件,请在底部):
32980.181 32011.917 32011.917: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin/ruby.vim
32980.516 32035.414 022.871: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin/eruby.vim
如您所见,为 Ruby 和 ERuby 加载 ftdetect 需要很长时间(时间显然以“毫秒”为单位)。将此与 HTML 的 ftdetect 以及加载我的 .vimrc 所需的时间进行比较:
952.223 000.626 000.626: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin/html.vim
738.536 612.248 534.785: sourcing $HOME/.vimrc
这正常吗?我能做些什么吗?不得不等待约 33 秒才能打开一个文件,这真是令人气愤。
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.022 000.022: --- VIM STARTING ---
012.064 012.042: Allocated generic buffers
012.910 000.846: locale set
013.186 000.276: clipboard setup
013.203 000.017: window checked
033.918 020.715: inits 1
034.697 000.779: parsing arguments
034.716 000.019: expanding arguments
077.784 043.068: shell init
079.520 001.736: Termcap init
079.562 000.042: inits 2
080.186 000.624: init highlight
179.889 001.991 001.991: sourcing /Users/davidtuite/.vim/autoload/pathogen.vim
564.261 000.178 000.178: sourcing /Users/davidtuite/.vim/filetype.vim
632.475 000.389 000.389: sourcing /Users/davidtuite/.vim/bundle/jst/ftdetect/jst.vim
633.141 055.478 055.089: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/filetype.vim
660.587 000.236 000.236: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin.vim
661.081 000.247 000.247: sourcing /Users/davidtuite/.vim/filetype.vim
661.408 000.041 000.041: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/filetype.vim
673.005 000.208 000.208: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/indent.vim
699.170 000.901 000.901: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/syncolor.vim
699.550 007.236 006.335: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/synload.vim
699.669 008.305 001.069: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/syntax.vim
700.763 000.561 000.561: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/syncolor.vim
715.774 000.497 000.497: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/syncolor.vim
716.658 000.452 000.452: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/syncolor.vim
722.467 010.218 009.269: sourcing /Users/davidtuite/.vim/bundle/solarized/colors/solarized.vim
738.536 612.248 534.785: sourcing $HOME/.vimrc
738.593 046.159: sourcing vimrc file(s)
784.522 000.859 000.859: sourcing /Users/davidtuite/.vim/bundle/ctrlp/autoload/ctrlp/mrufiles.vim
785.378 045.922 045.063: sourcing /Users/davidtuite/.vim/bundle/ctrlp/plugin/ctrlp.vim
816.261 000.454 000.454: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/getscriptPlugin.vim
818.593 000.792 000.792: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/gzip.vim
820.050 000.921 000.921: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/matchparen.vim
830.405 002.463 002.463: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/netrwPlugin.vim
843.038 000.145 000.145: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/rrhelper.vim
850.425 000.293 000.293: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/spellfile.vim
851.617 000.671 000.671: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/tarPlugin.vim
852.558 000.509 000.509: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/tohtml.vim
853.470 000.599 000.599: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/vimballPlugin.vim
854.255 000.463 000.463: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/plugin/zipPlugin.vim
854.362 062.537: loading plugins
854.375 000.013: inits 3
875.931 021.556: reading viminfo
875.995 000.064: setting raw mode
876.010 000.015: start termcap
876.062 000.052: clearing screen
952.223 000.626 000.626: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin/html.vim
32980.181 32011.917 32011.917: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin/ruby.vim
32980.516 32035.414 022.871: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/ftplugin/eruby.vim
33007.912 000.688 000.688: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/indent/ruby.vim
33024.997 001.804 001.804: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/indent/html.vim
33025.207 025.843 023.351: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/indent/eruby.vim
33067.541 000.929 000.929: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/javascript.vim
33085.205 004.486 004.486: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/vb.vim
33088.445 002.575 002.575: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/css.vim
33089.314 039.262 031.272: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/html.vim
33106.920 003.463 003.463: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/ruby.vim
33107.112 064.122 021.397: sourcing /usr/local/Cellar/vim/7.3.266/share/vim/vim73/syntax/eruby.vim
33107.888 107.447: opening buffers
33108.114 000.226: BufEnter autocommands
33108.117 000.003: editing files in windows
33108.319 000.202: VimEnter autocommands
33108.320 000.001: before starting main loop
33127.031 018.711: first screen update
33127.033 000.002: --- VIM STARTED ---
最佳答案
延迟是由于 ftplugin/ruby.vim 查询 Ruby 加载路径造成的。就在几天前,我通过放弃对 Ruby Gems 的查询显着提高了速度。我的 Mac 目前报告它需要大约 125 毫秒,这是一个显着的改进。所以您可以尝试更新到最新版本。
如果这还不够,您可以通过在 vimrc 中设置 g:ruby_path 来完全禁用加载路径查询。
尝试将其添加到 .vimrc 文件(在您的主文件夹中):
if !empty($MY_RUBY_HOME)
let g:ruby_path = join(split(glob($MY_RUBY_HOME.'/lib/ruby/*.*')."\n".glob($MY_RUBY_HOME.'/lib/rubysite_ruby/*'),"\n"),',')
endif
关于ruby - Vim 需要很长时间才能打开 Ruby 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13259173/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
这似乎应该有一个直截了当的答案,但在Google上花了很多时间,所以我找不到它。这可能是缺少正确关键字的情况。在我的RoR应用程序中,我有几个模型共享一种特定类型的字符串属性,该属性具有特殊验证和其他功能。我能想到的最接近的类似示例是表示URL的字符串。这会导致模型中出现大量重复(甚至单元测试中会出现更多重复),但我不确定如何让它更DRY。我能想到几个可能的方向...按照“validates_url_format_of”插件,但这只会让验证干给这个特殊的字符串它自己的模型,但这看起来很像重溶液为这个特殊的字符串创建一个ruby类,但是我如何得到ActiveRecord关联这个类模型
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits