如何在 vim 中启用 ruby​​ 方法可视化

发布于 2024-08-12 07:31:46 字数 610 浏览 4 评论 0 原文

a 已经用谷歌搜索了这个问题,但什么也没找到 - 也许我不知道在这种情况下如何正确定义搜索关键字。

当我开发 Ruby on Rails 应用程序时,我喜欢在 vim 中使用折叠。我的 Foldcolumn 设置为 4。但是它对 ruby​​ 方法的开始和结束的可视化并不是那么简单和明显(“-” - “def”,“|” - “end”):

-def foo
      bar = 1
|end

问题是 - 是有任何 vim 插件,它将在每个“def”和“end”附近显示标记(箭头或 stmh),就像在 TextMate 中所做的那样(1)?

v def foo
      bar = 1
^ end

另外,由于我在 vim/ruby 方面没有太多经验,也许还有另一种更优雅的方法来检查所有防御端对是否在特定文件中关闭? (matchit.vim 不太适合这种需求) 我希望有比在控制台中读取“语法错误”更方便的方法来捕捉丢失的“结束”:)

a have googled the question, but found nothing - maybe I do not know how to define the search keywords properly in this case.

I like to use folding in vim when I'm developing Ruby on Rails applications. And my foldcolumn is set to 4. But its visualizing of the start and the end of the ruby method is not so simple and obvious ("-" - "def", "|" - "end"):

-def foo
      bar = 1
|end

The question is - is there any plugin for vim, that will show markers (arrows or stmh) near every "def" and "end" like it is done in TextMate (1)?

v def foo
      bar = 1
^ end

Also, as I do not have much experience in vim/ruby, maybe there is another, more elegant way to check that all def-end pairs are closed in a particular file? (matchit.vim is not very comfortable for this need)
I hope there is more convenient way to catch lost "ends" than to read "Syntax error" in the console :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福丶如此 2024-08-19 07:31:46

我不确定这是否正是您所需要的,但是您尝试过“foldcolumn”选项吗?例如,使用:

:set foldcolumn=4

您将得到如下内容:

-   def foo
|       bar = 1
|   end

-   def foo2
|       bar = 2
|-      if x == 1
||          bar = 3
||      end
|   end

有关详细信息,请参阅 :help 'foldcolumn'。请注意,如果您的 Vim 启用了鼠标,则可以单击 - 符号来关闭折叠。

编辑

如果你不喜欢折叠方法,你可以使用符号(假设你的 Vim 启用了符号)。尝试这样的事情:

command! RubySigns call RubySigns()
" Optional:
au BufReadPost *.rb call RubySigns()
function! RubySigns()
    sign define ruby_end text=^
    sign define ruby_def text=v
    sign unplace *
    g/^\s*\(def\|class\|begin\)\>/exe 'sign place '.line('.').' line='.line('.').' name=ruby_def buffer='.bufnr('%')
    g/^\s*end\>/exe 'sign place '.line('.').' line='.line('.').' name=ruby_end buffer='.bufnr('%')
endfunction

它可能并不完美(我不知道 ruby​​),但它可能会给你一些入门的东西。

I'm not sure whether it's quite what you need, but have you tried the 'foldcolumn' option? For example, with:

:set foldcolumn=4

You'll get something like this:

-   def foo
|       bar = 1
|   end

-   def foo2
|       bar = 2
|-      if x == 1
||          bar = 3
||      end
|   end

See :help 'foldcolumn' for more information. Note that you can click on the - signs to close the folds if your Vim is mouse-enabled.

Edit

If you don't like the fold method, you could use signs (assuming your Vim is signs enabled). Try something like this:

command! RubySigns call RubySigns()
" Optional:
au BufReadPost *.rb call RubySigns()
function! RubySigns()
    sign define ruby_end text=^
    sign define ruby_def text=v
    sign unplace *
    g/^\s*\(def\|class\|begin\)\>/exe 'sign place '.line('.').' line='.line('.').' name=ruby_def buffer='.bufnr('%')
    g/^\s*end\>/exe 'sign place '.line('.').' line='.line('.').' name=ruby_end buffer='.bufnr('%')
endfunction

It's probably not perfect (I don't know ruby), but it might give you something to get started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文