Vim中折叠bash函数的问题 [英] A problem with folding bash functions in vim

查看:41
本文介绍了Vim中折叠bash函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以函数定义开头的bash脚本文件,如下所示:

I have a bash script file which starts with a function definition, like this:

#!/bin/bash
# .....
# .....
function test {
...
...
}
...
...

我使用vim 7.2,并且设置了 g:sh_fold_enabled = 1 ,以便使用bash启用折叠.问题是功能测试的折叠未正确结束,即,它一直持续到文件结束为止.看起来像这样:

I use vim 7.2, and I have set g:sh_fold_enabled=1 such that folding is enabled with bash. The problem is that the folding of the function test is not ended correctly, i.e. it lasts until the end of file. It looks something like this:

#!/bin/bash
# .....
# .....
+-- 550 lines: function test {----------------------------------------
~
~

该函数本身只有大约40行,我想要看起来像这样的东西(图像"说的不仅仅是千篇一律的单词,他们说的是...):

The function itself is just about 40 lines, and I want something that lookes like this ("images" say more than a thousend words, they say...):

#!/bin/bash
# .....
# .....
+-- 40 lines: function test {----------------------------------------
...
...
...
~
~

有人知道这个问题的解决方案吗?

Does anyone know a good solution to this problem?

推荐答案

我进行了一些研究,找到了解决问题的方法:要停止vim折叠功能直到文件结束,我必须添加一个跳过-对 shExpr 的语法区域的声明(在文件 sh.vim 中,通常放在/usr/share/vim/vim70/syntax/):

I have done some research, and found a way to fix the problem: To stop vim from folding functions until the end of file, I had to add a skip-statement to the syntax region for shExpr (in the file sh.vim, usually placed somewhere like /usr/share/vim/vim70/syntax/):

syn region shExpr ... start="{" skip="^function.*\_s\={" end="}" ...

此更改使语法文件不再认为 {} 属于shExpr组,而实际上它们属于功能组.还是我一直都这样理解.

This change stops the syntax file from thinking that the { and } belongs to the shExpr group, when they actually belong to the function group. Or that is how I have understood it, anyway.

注意:此修复程序仅适用于以下语法:

Note: This fix only works for the following syntax:

function test
{
....
}

而不是这样:

function test {
....
}

对最后一个错误的快速而肮脏的修复是从@shFunctionList群集中删除shExpr.

A quick and dirty fix for the last bug is to remove shExpr from the @shFunctionList cluster.

这篇关于Vim中折叠bash函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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