在 Vim 中,您最喜欢的 HTML、Javascript 和 CSS 折叠方法(或秘密技术)是什么?

发布于 2024-08-19 17:52:50 字数 1431 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请帮我爱他 2024-08-26 17:52:50

我使用 foldmethod=marker 并通过映射输入

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

所以当它折叠时,我立即看到折叠包含的内容,而不需要添加额外的注释。

对于 CSS,它更容易,我只需使用 foldmarker={,} ,所有定义都会自动折叠,向我显示所有类、标签和 id 的非常清晰的列表,我可以在需要时打开它们。实际上我所有的 CSS 文件最后都有这一行:

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

如果您愿意,您还可以直观地选择要折叠的区域并按 zf

I use foldmethod=marker and have mappings to enter <!-- {{{ --> and <!-- }}} --> where I want the fold to start and end. I put the start marker on the line with the opening block tag like:

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

so when it's folded I immediately see what the fold contains without the need to add extra comment.

For CSS it's even easier, I just use foldmarker={,} and all definitions are automagically folded showing me just a very clear list of all classes, tags and ids which I can open just when I need them. Actually 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 fold and press zf if you prefer.

时间海 2024-08-26 17:52:50

我在 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

缩进对于大多数美化的 html 来说效果很好,但我使用标记来进行大型声明性目录样式折叠文档。根据文件的编写者,其中一个会比另一个工作得更好,因此您需要快速访问这两个文件。

I flip between indent 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

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

陌生 2024-08-26 17:52:50

vim for html 的最佳折叠方法:使用 haml。 css 的最佳选择:使用 sass

我其实是认真的。它们使它变得更加紧凑。

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

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

記柔刀 2024-08-26 17:52:50

我几乎只使用了foldmethod=ignore。然而,我希望忽略的行默认为上面或下面的行的较高折叠级别,而不是较低的,启发了以下内容:(

" 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('

对语法突出显示感到抱歉...)

我使用它作为自定义插件,让单个文件类型覆盖它。例如,Python 不想查看前面的行,而只想查看后面的行。

) 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

对语法突出显示感到抱歉...)

我使用它作为自定义插件,让单个文件类型覆盖它。例如,Python 不想查看前面的行,而只想查看后面的行。

I have used foldmethod=ignore almost exclusively. However, my desire to have ignored lines default to the higher fold level of the above or below lines, instead of the lower, 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('

(Sorry about the syntax highlighting...)

I use that as a custom plugin, letting individual filetypes override it. Python, for example, doesn't want to look at previous lines, just following ones.

) 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 about the syntax highlighting...)

I use that as a custom plugin, letting individual filetypes override it. Python, for example, doesn't want to look at previous lines, just following ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文