What is your favorite bending method (or secret technique) in Vim for HTML, Javascript, and CSS?

I use something like this: 1,40 fo , but I think this is not the most efficient way.

What's yours

+6
vim fold
source share
4 answers

I use foldmethod=marker and have mappings for input <!-- {{{ --> and <!-- }}} --> , where I want the summary to start and end. I put the start marker on the line with the tag of the opening block, for example:

 <div id="topmenu"> <!-- {{{ --> 

therefore, when it develops, I immediately see what develops, without the need to add an additional comment.

For CSS, it's even simpler, I just use foldmarker={,} , and all the definitions automatically add up, showing me only a very clear list of all the classes, tags and identifiers that I can open only when I need them. In fact, all my CSS files have this line at the very end:

 /* vim: set fdm=marker fmr={,}: */ 

You can also visually select the region you want to reset, and press zf if you want.

+8
source share

I flip between indentation and marker with this in my vimrc ..

 let g:FoldMethod = 0 map <leader>ff :call ToggleFold()<cr> fun! ToggleFold() if g:FoldMethod == 0 exe 'set foldmethod=indent' let g:FoldMethod = 1 else exe 'set foldmethod=marker' let g:FoldMethod = 0 endif endfun 

Indentation works fine for most decorated html, but I use a marker for a large declarative table of contents for the style of folding documents. Depending on who wrote the file, one will work better than the other, so you need quick access to both.

+5
source share

Best folding method for vim for html: use haml instead . Best option for css: use sass instead .

I'm really serious. They make it much more compact.

+3
source share

I used foldmethod=ignore almost exclusively. However, my desire to ignore the default lines to a higher level of addition above or below the lines, and not below, inspired the following:

 " Default foldmethod " Similar to fdm=indent, but lets blank and comment lines default high. set fen fdm=expr fdi= set foldexpr=EswaldFoldLevel(v:lnum) function! EswaldFoldLevel(lnum) let ignored = '^\s*\([#/*]\|$\)' if getline(a:lnum) !~ ignored " In the general case, just use the indent level. " It would be nice if it didn't skip several levels... return indent(a:lnum) / &sw endif let previndent = 0 let prevnum = a:lnum - 1 while prevnum > 0 if getline(prevnum) =~ ignored let prevnum = prevnum - 1 else let previndent = indent(prevnum) / &sw break endif endwhile let nextindent = 0 let maxline = line('$') let nextnum = a:lnum + 1 while nextnum <= maxline if getline(nextnum) =~ ignored let nextnum = nextnum + 1 else let nextindent = indent(nextnum) / &sw break endif endwhile return max([previndent, nextindent]) endfunction 

(Sorry for the syntax highlighting ...)

I use this as a custom plugin, allowing individual file types to override it. For example, Python does not want to look at the previous lines, only the following.

+1
source share

All Articles