Created
May 2, 2009 03:21
-
-
Save rampion/105389 to your computer and use it in GitHub Desktop.
vim plugin for using numbered temp files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ~/.vim/plugin/nextunused.vim | |
" find the next unused filename that matches the given pattern | |
" counting up from 0. The pattern is used by printf(), | |
" so use 'temp%d.txt' for 'temp0.txt' to 'temp99999.txt' and | |
" 'temp%04d.txt' for 'temp0000.txt' to 'temp9999.txt'. | |
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 | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment