2012-08-06 41 views
0

我已經安裝了nodejs和jslint並在ftplugin目錄下創建了javascript.vim文件。 javascript.vim containes以下行:vim map切換鍵使JSLint

setlocal makeprg=jslint\ % 
setlocal errorformat=%f:%l:%c:%m 

nmap <F5> :w<CR>:make<CR>:cw<CR><CR>:copen<CR> 

爲JSLint的報告的錯誤,這將打開快速修復窗口。現在我想使用F5作爲第一個F5上的切換鍵運行make並在第二個F5關閉錯誤窗口上顯示錯誤窗口。

我已經創建了下面的代碼爲這個

setlocal makeprg=jslint\ % 
setlocal errorformat=%f:%l:%c:%m 

let s:showMakeWnd = "0" 
function! ToggleMake() 
    echo "Make Wnd mode: " . s:showMakeWnd 

    if s:showMakeWnd == "0" 
     execute ":w<CR>:make<CR>:cw<CR>:copen<CR>" 
    elseif 
     execute ":cclose<CR>" 
    endif 

    let s:showMakeWnd = (s:showMakeWnd == "0" ? "1" : "0") 
endfunction 

nmap <F5> :call ToggleMake()<CR> 

,但我按F5後,我收到以下錯誤:

"<CR>:make<CR>:cw<CR>:copen<CR>" 
Error detected while processing function ToggleMake: 
line 10: 
"<CR>:make<CR>:cw<CR>:copen<CR>" E212: Can't open file for writing 
+0

當你碰到''並且得到那個錯誤時,你是在quickfix窗口嗎? – romainl 2012-08-06 08:15:10

回答

0

execute執行防爆命令。而你只需要它來擴展變量,你不這樣做,那麼

execute ":w<CR>:make<CR>:cw<CR>:copen<CR>" 

你應該寫

w 
make 
cw 
copen 

你想要的語法爲normal命令

但它是不必要的更脆弱(我不確定這裏的特殊字符;常見的用法是exe "norm something",其中東西獲得一些變量替換。