Technology
 

Hide all functions in your code

From Vim Tips Wiki

(Redirected from VimTip240)

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 240 Previous Next created May 2, 2002 · complexity intermediate · author Wenzhi Liang · version 6.0


This tip is deprecated for the following reasons:

The official c.vim syntax file defines syntax folding already. To hide all functions you can just set fdm to syntax and then do a zM to close every fold.

Xemacs has a hide all function which can make all the function in your C file a fold and close them. And here is something small to achieve similiar under Vim.

func! HideAll()
  syn region myFold start="{" end="}" transparent fold
  syn sync fromstart
  set foldnestmax=1
  set foldmethod=syntax
endfunc
amenu Whatever.Hide\ all :call HideAll()<CR>

[edit] Comments

It works fine in version 6.0. But in version 6.1, it is really ugly. Suppose, you have the following java file:

public class Hello {
 public void setter() {
 // do something ...
 }
}

In 6.0, you will the individual method name (i.e., you will see the Hello and setter. So you can unfold the level you want. But in 6.1, you only see only big level that is the Hello. If you want to the method name -- setter, you have to unfold the Hello first. This is really inconvenient. I am not sure this is a "new feature" or simply a bad bug.


No they both work for me. Maybe you forgot :set foldnestmax=2


Yes, it works fine after I set the foldnestmax=2.


That's really neat. Now how do I get it to automatically apply to any .c .C .cc .cpp file I open? And is doing that a good idea?


Add the following after your autocmd for c files (and after you define the function)

autocmd FileType c,cxx,cpp call HideAll()