在Vim中折叠Scala导入

佩泰斯塔

打开Scala文件时,我试图让我的Vim安装程序自动折叠导入语句。这与打开文件时Intellij的操作类似。我目前.vimrcWiki的文件中包含以下几行

set foldmethod=syntax
set foldenable
syn region foldImports start=/(^\s*^import\) .\+/ end=/^\s*$/ transparent fold keepend

但是,当我打开.scala文件时,它不会折叠导入内容,而是折叠对象的主体。我也在使用vim-scala插件谢谢您的帮助!

在此处输入图片说明

和布拉德伯里

您几乎可以使它正常工作。我们应该考虑一些时髦的因素。

  • 设置foldmethodsyntax(顺便说一句,这在学习Vimscript the Hardway上没有记录。.so:help foldmethod是弄清楚这一点的关键)

SYNTAX fold-syntax

A fold is defined by syntax items that have the "fold" argument. |:syn-fold|

The fold level is defined by nesting folds. The nesting of folds is limited with 'foldnestmax'.

Be careful to specify proper syntax syncing. If this is not done right, folds may differ from the displayed highlighting. This is especially relevant when using patterns that match more than one line. In case of doubt, try using brute-force syncing:

    :syn sync fromstart

The main thing to note is the sync fromstart this is a useful helper if you have regex that would match throughout the file and only want to catch the header. In your case you should be able to ignore this but just something to be aware of.

  • top down regex scanning

由于import块是相当可预测的,因此我们可以简化startend看起来像这样:

syn region foldImports start="import" end=/import.*\n^$/ fold keepend

由于region只是在寻找一些字符串来开始匹配,因此我们可以使用"import"(或/import/),然后对于结束值,我们想使用一些经过精心设计的语句。关键是我们要使结尾为导入最后一行,其后是空白行(/import.*\n^$/

希望这可以为您解决问题(我不使用scala,因此您可能需要根据需要调整正则表达式)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在VIM中折叠代码

来自分类Dev

在vim中禁用折叠注释

来自分类Dev

自动折叠Vim中的代码块

来自分类Dev

在vim中折叠代码使我感到困惑

来自分类Dev

如何在Vim中折叠类块?

来自分类Dev

在vim中折叠代码使我感到困惑

来自分类Dev

在(n)vim中手动触发Scala Metals构建导入

来自分类Dev

在Scala中折叠类似的案例陈述

来自分类Dev

并行集合中scala折叠的行为

来自分类Dev

Tuple(int,int)中的Scala条件折叠

来自分类Dev

方法中的Scala导入语句

来自分类Dev

如何在Vim中的{{{和}}}之间折叠所有代码

来自分类Dev

E490:在vim的unix中找不到折叠

来自分类Dev

摆脱Vim折叠名称中的下划线

来自分类Dev

如何在ViM中折叠数据文件?

来自分类Dev

如何在Vim中启用和使用代码折叠?

来自分类Dev

在Vim中按za时找不到折叠错误

来自分类Dev

如何在C类程序中在Vim中使用折叠

来自分类Dev

在vim中折叠一个预定义的语法区域

来自分类Dev

摆脱Vim折叠名称中的下划线

来自分类Dev

vim中的python:导入行上的'gf'

来自分类Dev

VIM:折叠子弹点

来自分类Dev

折叠Scala序列中匹配元素的子序列

来自分类Dev

使用折叠计数Scala列表中的Int数量

来自分类Dev

Scala | 在二叉树中折叠

来自分类Dev

折叠Scala序列中匹配元素的子序列

来自分类Dev

Vim离开折叠时自动折叠

来自分类Dev

Vim离开折叠时自动折叠

来自分类Dev

从Scala中的其他类导入函数