將下面的~/.vim/plugin/nextunused.vim
" nextunused.vim
" find the next unused filename that matches the given pattern
" counting up from 0. The pattern is used by printf(), so use %d for
" an integer and %03d for an integer left padded with zeroes of length 3.
function! GetNextUnused(pattern)
let i = 0
while filereadable(printf(a:pattern,i))
let i += 1
endwhile
return printf(a:pattern,i)
endfunction
" edit the next unused filename that matches the given pattern
command! -nargs=1 EditNextUnused :execute ':e ' . GetNextUnused('<args>')
" write the current buffer to the next unused filename that matches the given pattern
command! -nargs=1 WriteNextUnused :execute ':w ' . GetNextUnused('<args>')
" To use, try
" :EditNextUnused temp%d.txt
"
" or
"
" :WriteNextUnused path/to/file%03d.extension
"
所以,如果你在temp0000.txt
通過temp0100.txt
都已經使用 目錄和你做:WriteNextUnused temp%04d.txt
,它將當前緩衝區寫入temp0101.txt
。
+1對於純vim和注意需要python – ojblass 2009-05-02 05:24:26