0

autocmd VimResized * <foo><foo>每当调整 vim 应用程序的窗口大小时,都会运行该命令。有没有办法根据调整大小是缩小还是增长来运行不同的命令?如果是这样,控制台 vim 是否有任何警告?

4

1 回答 1

0

窗口是二维的,因此缩小或增长的概念非常不精确:您是在谈论高度,还是宽度,还是面积?

假设您正在谈论该地区。

一种简单的方法是在启动时和每次调整 win 大小时保存窗口的最后大小;那么你只需要比较最后一个大小和新的大小,每次调整胜利的大小:

" Defines a command to save the current dims:
command! SaveVimDims let g:last_lines=&lines | let g:last_columns=&columns

" Saves the dims on startup:
au VimEnter * SaveVimDims

" Calls the func below, each the win is resized:
au VimResized * call VimResized_Func()

function! VimResized_Func()
    " Gets the area of the last dims:
    let last_area = g:last_lines * g:last_columns

    " Saves the new dims:
    SaveVimDims

    " Gets the area of the new dims:
    let cur_area = g:last_lines * g:last_columns

    " Compares the areas:
    if cur_area < last_area
        " do something when shrinking
    else
        " do something when growing
    endif
endf

这只用 Gvim 测试过;我从不在控制台中使用 Vim。希望它也能正常工作

于 2016-02-24T21:10:13.947 回答