おかげで、私は彼の主要なアイデアを取り、それを改善しています。私は改善するために何を望むか:
- 私たちは、代わりに標準
:so
の追加のユーザー指定のコマンド:Execute
を使用する必要があります([OK]を、私たちはユーザー指定のコマンド:So
に名前を付けることができ、いずれにせよ、それはコマンドの新しい大文字のバージョンを使用して迷惑なんです)
- 副作用がほとんどありません:コマンドを実行すると、レジスタ
@z
が壊れています。以下の私のスクリプトで
、我々は以前のように:so {file}
コマンドを使用することができ、我々はまた、範囲でそれを使用することができます::'<,'>so
(実際:'<,'>Source
に展開する)
ここ
:
" This script provides :Source command, a drop-in replacement for
" built-in :source command, but this one also can take range and execute just
" a part of the buffer.
"
" Sources given range of the buffer
function! <SID>SourcePart(line1, line2)
let tmp = @z
silent exec a:line1.",".a:line2."yank z"
let @z = substitute(@z, '\n\s*\\', '', 'g')
@z
let @z = tmp
endfunction
" if some argument is given, this command calls built-in command :source with
" given arguments; otherwise calls function <SID>SourcePart() which sources
" visually selected lines of the buffer.
command! -nargs=? -bar -range Source if empty("<args>") | call <SID>SourcePart(<line1>, <line2>) | else | exec "so <args>" | endif
" in order to achieve _real_ drop-in replacement, I like to abbreviate
" existing :so[urce] command to the new one.
"
" So, we can call :so % just as before, and we are also call '<,'>so
cnoreabbr so Source
cnoreabbr sou Source
cnoreabbr sour Source
cnoreabbr sourc Source
cnoreabbr source Source
'cnoreabbr'を使うときは注意が必要です。予期しない場所で展開されます。検索。詳細については、この記事を参照してくださいhttp://stackoverflow.com/questions/7513380/vim-change-x-function-to-delete-buffer-instead-of-save-quit –
@PeterRincker、あなたのノートに感謝します。 。 –