使用 .vimrc 在 Vim 中自动折叠 Oracle 内联视图
我之前见过神奇的 Vim 命令,您可以将其添加到 .vimrc 中,以便在打开特定类型的文件时创建折叠。我记得有这样的代码,可以在打开文件时在每个 Ruby 方法和类中创建折叠。然后,通过一个命令,我可以折叠所有这些方法折叠。有谁知道如何在 PL/SQL 中使用内联视图来做到这一点?假设我有以下 SQL:
SELECT blah,
teh_max
FROM (
SELECT blah,
MAX(bar) AS teh_max
FROM (
SELECT blah,
bar
FROM foo
)
GROUP BY blah
)
ORDER BY blah
我希望在 Vim 中打开它时创建折叠,以便我可以转到 FROM (
行,在命令模式下点击 zc
,并折叠从该行开始的内联视图,也可以用一个命令折叠所有折叠。
I've seen magical Vim commands before that you could add to your .vimrc to have folds created upon opening a particular type of file. I remember having such code that would create the folds, upon opening the file, at every Ruby method and class. Then, with one command, I could collapse all those method folds. Does anyone know how to do this with inline views in PL/SQL? Say I have the following SQL:
SELECT blah,
teh_max
FROM (
SELECT blah,
MAX(bar) AS teh_max
FROM (
SELECT blah,
bar
FROM foo
)
GROUP BY blah
)
ORDER BY blah
I would like folds to be created when I open this in Vim so that I can go to a FROM (
line, hit zc
in command mode, and have the inline view starting at that line be collapsed. It would be nice to collapse all the folds with one command, too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将
foldmethod
设置为syntax
来激活基于语法的折叠:然后必须在语法定义中指定折叠,这是通过提供
fold
来完成的> 应该增加折叠级别的区域的参数。引用文档:因此,您必须进入您关心的任何文件类型的语法文件,并将
fold
参数添加到适当的区域,或者可能添加您自己的区域。在你的例子中,它看起来与 C/C++ 语法的大括号折叠非常相似,除了括号之外。默认语法文件通常保存在 Linux 上的
/usr/share/vim/vimXX/syntax
中(Windows 上大概保存在\vimXX\syntax
中? ) 其中 XX 是不带句点的版本号(例如 72)。这些可以在系统范围内被/usr/share/vim/vimfiles/syntax
中的文件覆盖,也可以在每个用户的~/.vim/syntax
中被文件覆盖。Folding based on syntax is activated by setting
foldmethod
tosyntax
:The folding must then be specified within the syntax definition, which is done by providing the
fold
argument to regions which should increase the fold level. To quote the documentation:So you'll have to go into the syntax files for whatever filetypes you care about, and add the
fold
argument to the appropriate regions, or potentially add in your own regions. In your case, it looks like it's fairly similar to the C/C++ syntax's fold-by-braces, except with parentheses.The default syntax files are generally kept in
/usr/share/vim/vimXX/syntax
on Linux (and presumably<vim-directory>\vimXX\syntax
on windows?) where XX is the version number without the period (e.g. 72). These may be overridden system-wide by files in/usr/share/vim/vimfiles/syntax
or per-user by files in~/.vim/syntax
.我建议避免多级 SQL 查询。您始终可以创建视图、临时表。我知道这与汤姆·凯特的理论相矛盾,但是
这是 10 年的 PL/SQL 实践。把复杂的程序分成几个简单的程序
部分。将复杂的 SQL 查询分成简单的查询。
在您的示例中,查询很容易掌握,折叠只会造成干扰。
相反,对于嵌套 PL/SQL 过程,折叠非常有用。 vim.org 上有一个 VIM 脚本。
I would suggest just to avoid multilevel SQL queries. You can always create a view, a temporary table. I know that contradicts with the theory of Tom Kyte, but
it's the 10 years PL/SQL practice. Divide the complex program into several simpler
parts. Divide the complex SQL queries into simple queries.
In your example, the query is quite easy to grasp, folding would only disturb.
On the opposite for nested PL/SQL procedures folding works quite usefully. There is a script for VIM on vim.org.