2016-09-30 25 views
0

我有以下的Vimscript函數內部:編程均衡窗函數

function! WindowCommand(cmd) 
    execute a:cmd 
    if !g:golden_ratio_enabled 
     normal <C-w>= 
    endif 
endfunction 

我用它像這樣:

map <space>w/ :call WindowCommand(':vs')<cr> 

它應該以均衡的窗口,但只有當g:golden_ratio_enabled是0,否則它不應該做任何事情。

它不工作,雖然,我不知道爲什麼,因爲下面沒有工作:

map <space>w/ :vs<cr><C-w>= 

我在做什麼錯在這裏?

回答

2

有幾個修復程序。謝天謝地,修復非常簡單

無論出於何種原因,normal <C-w>foo不起作用;您必須改用wincmd。從:h wincmd

     *:winc* *:wincmd* 
These commands can also be executed with ":wincmd": 

:[count]winc[md] {arg} 
     Like executing CTRL-W [count] {arg}. Example: > 
      :wincmd j 
     Moves to the window below the current one. 
     This command is useful when a Normal mode cannot be used (for 
     the |CursorHold| autocommand event). Or when a Normal mode 
     command is inconvenient. 
     The count can also be a window number. Example: > 
      :exe nr . "wincmd w" 
     This goes to window "nr". 

因此,在這種情況下,你應該做的

wincmd = 

或者,你可以輸入文字<C-w>字符,通過鍵入<C-v><C-w>。在你的vim會話中,這個字符將顯示爲^W

1

要與<notation>執行動作,而不是使用:

:exe "normal \<notation>" 

我用了很多調試映射。

但是在這種情況下,確實更喜歡wincmd