简体   繁体   English

缺省打开project.vim中的所有折叠

[英]open all folds in project.vim by default

When opening the project window for the first time in vim, all folds are closed. 在vim中首次打开项目窗口时,所有折叠均关闭。 I find this very annoying. 我觉得这很烦人。 Is there any way to have them all open by default? 有没有办法让它们默认都打开? I've read trough all of the documentation for project.vim but couldn't find a setting for this. 我已经阅读了project.vim的所有文档,但找不到相应的设置。

Put this in your .vimrc to set all folds to open when you open a file: 将其放在.vimrc中以设置打开文件时所有折叠的打开:

set foldlevel=99

That will cause all 99th level folds to be closed, which I hope is none of them. 这将导致所有第99级折页都被关闭,我希望这些都不是。 If you have more than 99 levels of folds, you have a 99 problems joke. 如果您有超过99个级别的弃牌,则有99个问题笑话。

How about an autocmd? autocmd怎么样?

Assuming you use the default projects filename, you could do something like this: 假设您使用默认项目文件名,则可以执行以下操作:

autocmd BufEnter .vimprojects silent! %foldopen!

If you want to maintain the cursor position, you could either clobber a mark or use a variable: 如果要保持光标位置,则可以破坏标记或使用变量:

autocmd BufEnter .vimprojects let PreFoldPosition = getpos('.') | silent! %foldopen! | call setpos('.', PreFoldPosition)

Edit 编辑

It seems that project.vim creates the buffer and then adds the contents. 似乎project.vim创建了缓冲区,然后添加了内容。 As a result of this, the autocmds above only work on the second and subsequent times the project window is opened. 结果,上面的autocmds仅在第二次及以后打开项目窗口时起作用。 The only way I know of to get round this is to edit project.vim and put silent! %foldopen! 我知道解决这个问题的唯一方法是编辑project.vimsilent! %foldopen! silent! %foldopen! near the end of the function s:Project(filename) . 在函数s:Project(filename)的结尾处。 It might be worth sending an email to the author and asking whether he could add a means of doing this (with an option) in the standard distribution. 可能值得向作者发送电子邮件,并询问他是否可以在标准发行版中添加这样做的方法(带有选项)。

I know this question is kind of old, but another solution is to create a function in your .bashrc (or similar) to do the following: 我知道这个问题有点陈旧,但是另一个解决方案是在.bashrc(或类似文件)中创建一个函数来执行以下操作:

vim +"Project $1" +'silent! %foldopen!'

For instance, in my .bashrc, I have the following: 例如,在我的.bashrc中,我具有以下内容:

export PROJECT_DIR="$HOME/devel/projects"

project()
{
    if test -z "$1"
    then
        echo "Usage: project <project name>"
    else
        if [ ! -e "$PROJECT_DIR/$1" ]
        then
            echo "Project not found. Available projects:"
            find $PROJECT_DIR/* | xargs -l basename
        else
            vim +"Project $PROJECT_DIR/$1" +'silent! %foldopen!'
        fi
    fi
}

_project()
{
    local cur
    local PROJECTS=`find $PROJECT_DIR/projects/* | xargs -l basename`
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    COMPREPLY=( $( compgen -W "$PROJECTS" -- $cur ) )
}
complete -F _project project

Which allows me to simply issue the 'project' command and tab-complete the name. 这使我可以简单地发出“项目”命令并使用制表符完成名称。

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

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