简体   繁体   English

我应该在VIM中使用什么折叠?

[英]What Fold should I use in VIM?

I usually edit RUBY files in VIM. 我通常在VIM中编辑RUBY文件。 I want the methods(def...end) to fold. 我希望方法(def ... end)折叠。 Could you please help me define the fold syntax? 你能帮我定一下折叠语法吗?

Assuming you've already got Ruby syntax highlighting setup and working, use the syntax mode for folding: 假设您已经使用Ruby语法突出显示设置和工作,请使用syntax模式进行折叠:

set foldmethod=syntax

This will give you folds on class .. end and def .. end , etc. 这将给你折叠class ... enddef .. end等。

I like to have everything fold by default, and this here will let you tweak a whole bunch of things related to folding. 我喜欢在默认情况下折叠所有东西,这里可以让你调整一大堆与折叠有关的东西。 I do mostly Perl and C++ coding and I find it works well with that. 我主要做Perl和C ++编码,我觉得它很适合。 Folding and unfolding is mapped to space key. 折叠和展开映射到空格键。

Here's what I have going in my vimrc: 这是我在vimrc中的内容:

  " Folding stuff
  hi Folded guibg=red guifg=Red cterm=bold ctermbg=DarkGrey ctermfg=lightblue
  hi FoldColumn guibg=grey78 gui=Bold guifg=DarkBlue
  set foldcolumn=2
  set foldclose=
  set foldmethod=indent
  set foldnestmax=10
  set foldlevel=0
  set fillchars=vert:\|,fold:\
  set foldminlines=1
 " Toggle fold state between closed and opened.
  "
  " If there is no fold at current line, just moves forward.
  " If it is present, reverse it's state.
  fu! ToggleFold()
     if foldlevel('.') == 0
         normal! l
     else
         if foldclosed('.') < 0
             . foldclose
         else
             . foldopen
         endif
     endif
     echo
  endf

" Map this function to Space key.
  noremap <space> :call ToggleFold()<CR>

I think you put the cursor on the first line then zfnj where n is the number of lines to fold (so to fold 10 lines you woudl zf10j). 我认为你把光标放在第一行然后是zfnj,其中n是要折叠的行数(所以折叠10行你woudl zf10j)。 I think it will also recognize syntax so like in PHP I do zf} to fold to the closing bracket. 我认为它也会识别语法,就像在PHP中我做zf}折叠到结束括号。 I don't code in Ruby, so I don't know if this works in Ruby. 我不用Ruby编写代码,所以我不知道这是否适用于Ruby。

From then on, to toggle, zo will open and zc will close. 从那时起,要切换,zo将打开,zc将关闭。

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

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