Vim的函数来更新类定义,以反映当前位置 [英] Vim function to update class definition to reflect current location

查看:316
本文介绍了Vim的函数来更新类定义,以反映当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把我的Vimscript到一个新的水平。作为后续行动,以我的了解从生成文件路径类的定义等问题,你将如何实现Vimscript中的以下?

由于我在的lib /富/酒吧/ buz.rb ,看起来像这样的文件:

 模块富
模块吧   班布斯
     ...
   结束结束
结束

如果我将文件移动到的lib /猫/狗/牛/ buz.rb ,我可以创建一个功能来快速更新文件,看起来像这样<? / p>

 模块猫
模块狗
模块牛  班布斯
    ...
  结束结束
结束
结束


解决方案

您可以使用扩大(%:P:H:T')来得到当前文件的目录。添加其他:小时修饰获得的父目录。参见:帮助文件名修饰语

替代('富','^','\\ U&放大器;','')将大写的第一个字母

要做好更换的缓冲器,:替代,可能与一个:帮助子取代-EX pression 就行了。

I'm trying to take my vimscript to the next level. As a follow up to my other question about generating a class definition from a file path, how would you implement the following in vimscript?

Given I have a file at lib/foo/bar/buz.rb that looks like this:

module Foo
module Bar

   class Buz
     ...
   end

end
end

If I move the file to lib/cat/dog/cow/buz.rb, can I create a function to quickly update the file to look like this?

module Cat
module Dog
module Cow

  class Buz
    ...
  end

end
end
end

解决方案

You can use expand('%:p:h:t') to get the current file's directory. Add additional :h modifiers to get parent directories. See :help filename-modifiers.

substitute('foo', '^.', '\u&', '') will upper-case the first letter.

To do the replacement in the buffer, a :substitute, probably with a :help sub-replace-expression will do.

这篇关于Vim的函数来更新类定义,以反映当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆