How to auto save vim session on quit and auto reload on start including split window state?

前端 未结 8 704
孤城傲影
孤城傲影 2020-12-13 04:35

I like to split my vim screen in 3. one :vsplit and one :split. I want these windows and the files I worked on to be saved when I close vim. I also want these windows to aut

8条回答
  •  暖寄归人
    2020-12-13 05:08

    i use vim for projects and every project have .vim folder in root of my project. and i use startup script for vim

        #!/bin/bash
    if [[ $# != 1 ]]
    then
        zenity --title "Vim IDE usage error" --error --text "Usage: vim_ide /path/to/project/dir."
        exit 1
    fi
    
    if [[ ! -e "$1/.vim/ide.vim" ]]
    then
        zenity --title "Vim IDE usage error" --error --text "'$1' is not a Vim IDE project directory."
        exit 1
    fi
    
    cd "$1" || { zenity --title "Vim IDE usage error" --error --text "Can't change current directory to Vim IDE project directory '$1'."; exit 1; }
    

    .vim/ide.vim

    set sessionoptions-=options
    au VimLeave * :mksession! .vim/ide.session
        if getfsize(".vim/ide.session") >= 0
            source .vim/ide.session
        endif
    

    so i start my vim by next command

    $~/ide.sh /path/to/project
    

    All my opened files, tabs and even position cursors are saved before exit and restored after start.

提交回复
热议问题