2012-08-27 33 views
0

說我是編輯我的vimrc文件Vim腳本文件的行,我輸入這行:如何運行的緩衝

let xxx = 1 

的話,我想測試這一行,我必須進入在正常模式下,按':'並將此行復制到命令迷你緩衝區中...

我可以配置vim來運行1-2行按鍵嗎? 或者更進一步,我可以通過1-2擊鍵運行突出顯示(可視模式)代碼區域嗎? 我想有人應該已經做了這樣的事情,但只是無法通過谷歌或在這裏找到它。

謝謝!

+3

認爲這主要是http://stackoverflow.com/questions/4725435/gvim-passing-the-visually-selected-text-to-the-command-line – moopet

+0

的副本看看zzappers優秀的Vim技巧指南。你的問題在http://rayninfo.co.uk/vimtips.html有答案 –

回答

0
":[range]Execute  Execute text lines as ex commands. 
"    Handles |line-continuation|. 
" The same can be achieved via "[email protected] (or [email protected]" through the unnamed register); 
" but there, the ex command must be preceded by a colon (i.e. :ex) 
command! -bar -range Execute silent <line1>,<line2>yank z | let @z = substitute(@z, '\n\s*\\', '', 'g') | @z 

" [count]<Leader>e Execute current [count] line(s) as ex commands, then 
" {Visual}<Leader>e jump to the following line (to allow speedy sequential 
"   execution of multiple lines). 
nnoremap <silent> <Leader>e :Execute<Bar>execute 'normal! ' . v:count1 . 'j'<CR> 
xnoremap <silent> <Leader>e :Execute<Bar>execute 'normal! ' . v:count1 . 'j'<CR>