代码之家  ›  专栏  ›  技术社区  ›  Stefano Borini

维姆打开我的糊折页。如何预防这种情况?

  •  2
  • Stefano Borini  · 技术社区  · 14 年前

    我的Fortran折叠有点奇怪。这是示例文件

    module foo
    contains
    subroutine hello()
    
    end subroutine hello
    subroutine hello()
    
    end subroutine
    
    subroutine hello()
    
    end subroutine
    end module foo
    
    subroutine hello()
    
    end subroutine
    subroutine hello()
    
    end subroutine
    subroutine hello()
    
    end subroutine
    

    这是VIMRC

    syntax on
    au! BufRead,BufNewFile *.f90 setfiletype fortran
    set foldmethod=syntax
    let fortran_fold=1
    

    烦人的事情如下。如果我剪切(dd)并粘贴(p)折叠子程序 外部 模块/结束模块块,新粘贴的折叠保持闭合。如果我粘贴它 里面 模块/结束模块块,新粘贴的折叠区域显示,而不是展开。你能重现这个问题吗(这里是VIM 7.2),你知道任何解决方法吗?

    1 回复  |  直到 14 年前
        1
  •  2
  •   eckes    14 年前

    我认为这不是特定的Fortran模块问题,而是一般的问题。

    有一个 vimtip 这为在编辑文件时意外打开折叠提供了解决方案。诀窍是设置 foldmethod manual 编辑开始时:

    autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
    

    完成编辑(或离开窗口)后,重置 折叠方法 原值:

    autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif