繁体   English   中英

在vim中禁用折叠注释

[英]Disable folding comments in vim

对于vim中的Javascript文件,有没有办法用foldmethod=syntax禁用折叠评论?

我在我的vimrc使用以下折叠代码:

if has("folding")
    set foldenable
    set foldopen=hor,search,tag,undo
    set fillchars=diff:\ ,fold:\ ,vert:\

    function! JavaScriptFold()
            setl foldmethod=syntax
            setl foldlevelstart=1
            syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
    endfunction
endif    

调用JavaScriptFold折叠以下代码:

/**
 * Hello, this is a comment.
 */
function hello() {
    console.log('hello');
}

进入这个:

+--  3 lines: *
+--  3 lines: function hello() {

我想让它折叠成这个:

/**
 * Hello, this is a comment.
 */
+--  3 lines: function hello() {

我通过C评论折叠的Stack Overflow问题找到了关于c_no_comment_fold ,但我找不到Javascript的等价物。 有没有办法做到这一点?

可用的JavaScript语法插件处于错误状态。 你正在使用的那个有点奇怪(定义一个启用(某些)折叠的函数,默认启用注释折叠),并且有未使用的配置变量( javaScript_fold ,它什么都不做)。

要禁用折叠注释,请直接编辑脚本并从syntax region javaScriptDocComment ...行中删除fold关键字,或将以下重新定义添加到~/.vim/after/syntax/javascript.vim

syntax clear javaScriptDocComment
syntax region javaScriptDocComment        matchgroup=javaScriptComment start="/\*\*\s*$"  end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,@javaScriptHtml,@Spell

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM