0

autocmd VimResized * <foo><foo>vim アプリケーションのウィンドウのサイズが変更されるたびにコマンドが実行されます。サイズ変更が縮小か拡大かによって異なるコマンドを実行する方法はありますか? もしそうなら、コンソール vim に関する警告はありますか?

4

1 に答える 1

0

ウィンドウは 2 次元であるため、縮小または拡大の概念は非常に不正確です。高さについて話しているのですか、それとも幅について話しているのですか、それとも面積について話しているのですか?

あなたがその地域について話しているとしましょう。

これを行う簡単な方法は、起動時と勝利のサイズが変更されるたびに、ウィンドウの最後のサイズを保存することです。次に、勝利のサイズが変更されるたびに、最後のサイズと新しいサイズを比較するだけです。

" 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 に答える