简体   繁体   English

在vim中禁用折叠注释

[英]Disable folding comments in vim

Is there a way to disable folding for comments with foldmethod=syntax for Javascript files in vim? 对于vim中的Javascript文件,有没有办法用foldmethod=syntax禁用折叠评论?

I'm using the following folding code in my vimrc : 我在我的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    

Calling JavaScriptFold folds the following code: 调用JavaScriptFold折叠以下代码:

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

into this: 进入这个:

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

I want it to get folded into this: 我想让它折叠成这个:

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

I found out about c_no_comment_fold via this Stack Overflow question on C comment folding , but I can't find an equivalent for Javascript. 我通过C评论折叠的Stack Overflow问题找到了关于c_no_comment_fold ,但我找不到Javascript的等价物。 Is there a way to do this? 有没有办法做到这一点?

The available JavaScript syntax plugins are in a bad state. 可用的JavaScript语法插件处于错误状态。 The one you're using is a bit weird (defining a function to enable (some) folding, with comment folding enabled by default), and has unused config variables ( javaScript_fold , which does nothing). 你正在使用的那个有点奇怪(定义一个启用(某些)折叠的函数,默认启用注释折叠),并且有未使用的配置变量( javaScript_fold ,它什么都不做)。

To disable folding for comments, either directly edit the script and remove the fold keyword from the syntax region javaScriptDocComment ... line, or add the following redefinition to ~/.vim/after/syntax/javascript.vim : 要禁用折叠注释,请直接编辑脚本并从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