资讯专栏INFORMATION COLUMN

Vim窗口布局保存插件

cnio / 2144人阅读

摘要:的分屏很好用,可以开多个窗口对照代码,但是分的屏多了,需要临时扩大某个窗口到最大,编辑代码,使用完成之后,又想要恢复原先已经设置好的布局,本身没有提供这样的功能,但是提供了实现这种功能的基础下面的代码就实现了这样的功能将下面的代码保存为放到

Vim 的分屏很好用,可以开多个窗口对照代码,但是分的屏多了,需要临时扩大某个窗口到最大,编辑代码,使用完成之后,又想要恢复原先已经设置好的布局,Vim本身没有提供这样的功能,但是提供了实现这种功能的基础, 下面的代码就实现了这样的功能. 将下面的代码保存为vimlayout.vim放到 Vim的plugin目录下, 设置自己喜欢的绑定键就可以了工作了. 此代码在 Vim 7.3中测试通过.

if exists("g:vimlayoutloaded")
    finish
else
    let g:vimlayoutloaded=1
endif

function! HeightToSize(height)
    let currwinno=winnr()
        if winheight(currwinno)>a:height
            while winheight(currwinno)>a:height
                execute "normal -"
            endwhile
        elseif winheight(currwinno)+"
            endwhile
        endif
endfunction

function! WidthToSize(width)
       let currwinno=winnr()
        if winwidth(currwinno)>a:width
            while winwidth(currwinno)>a:width
                execute "normal <"
            endwhile
        elseif winwidth(currwinno)>"
            endwhile
        endif
endfunction


function! TweakWinSize(orgisize)
    call HeightToSize(a:orgisize[0])
    call WidthToSize(a:orgisize[1])
endfunction

function! RestoreWinLayout()
    if exists("g:layout")
        let winno=1
        let orgiwinno=winnr()
        for win in g:layout
            execute "normal w"
            let currwinno=winnr()
            if currwinno!=1 && currwinno!=orgiwinno
                call TweakWinSize(g:layout[currwinno-1])
            endif
        endfor
        unlet g:layout
    endif
endfunction

function! SaveWinLayout()
    let wnumber=winnr("$")
    let winlist=range(wnumber)
    let winno=0
    let layout=[]
    for index in winlist
        let winno+=1
        let wininfo=[winheight(winno),winwidth(winno)]
        call add(layout,wininfo)
    endfor
    let g:layout=layout
endfunction

function! ToggleMaxWin()
    if exists("g:layout")
        if winnr("$")==len(g:layout)
            call RestoreWinLayout()
        else
            call SaveWinLayout()
            execute "normal 200>"
            execute "normal _"
            call RestoreWinLayout()
        endif
    else
        call SaveWinLayout()
        execute "normal 200>"
        execute "normal _"
    endif
endfunction

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/24761.html

相关文章

  • tmux的超绝便利

    摘要:服务器的任务不间断运行,就是利用了的特性。超绝常用操作快捷键参考。我的配置如下基础设置前缀绑定启用鼠标选中窗口将快捷键设置为模式 服务器的任务不间断运行,就是利用了tmux的特性。就是说,一般ssh是断开就会停止所有之前连接ssh期间运行的所有processes,而tmux的核心业务不在于把屏幕分成几块好看,而是它能保存session!而且还能多端实时直播session! 了解tmux...

    dunizb 评论0 收藏0
  • Vim的NerdTree插件

    摘要:一个项目文件多起来时,左边的文件树菜单是必要的。即使有相关的方法控制这些,只是作为一个文件菜单来说,这也太麻烦了。刷新正常下是不会自动刷新的,文件删除了,多了都不会自动显示。 一个项目文件多起来时,左边的文件树菜单是必要的。 参考:常用文件树快捷键所有命令及推荐键盘映射:官方 showImg(https://segmentfault.com/img/remote/14600000177...

    Mike617 评论0 收藏0

发表评论

0条评论

cnio

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<