Wednesday, May 15, 2013

The :next command with directories (bug?)

Hi,
I created this simple function/command to help me open more than 10 files or directories passed in at the vim command line in tabs since vim limits me to maximum 10 with the -p option. It is basically, looping argc() times issuing :tabnew and next commands every time.

-------------------------------------------------------
function! TabNewNext(...)
augroup temptnn
autocmd!

" When opening files which may be open elsewhere, open them in read only
" mode
au SwapExists * :let v:swapchoice='o'
augroup end
try
if a:0
let l:limit = abs(a:1)
else
let l:limit = 0
endif
let i = 0
" for all files or directories on the (g)vim command line
" open a new tab and issue the :next command
while i < argc() && (l:limit == 0 || i < l:limit)
tabnew
try
next
catch /E16[35]/
" E163 - There is only one file to edit
" E165 - Cannot go beyond last file
tabclose
exe ':tabp ' . (i + 1)
break
endtry
let i = i + 1
endwhile
finally
augroup! temptnn
endtry
endfunction

com! -nargs=? NT :call TabNewNext(<args>)
--------------------------------------------------

This works fine with files, but this fails in weird ways with directories when I do this:

% mkdir tk11
% mkdir tk22
% mkdir tk33
% mkdir tk44
% vim tk??

And then once inside vim

:NT

This opens tk11, tk22, tk22, tk33 and tk33 instead ok the usual tk11, tk22, tk33 and tk44 sequence. I've reproduced this with Vim 7.3 on Mac and FreeBSD (and probably Ubuntu also) and see the same behavior everywhere, with or without plugins disabled. What am I doing wrong here or is it a bug?
Also, vim -p tk?? works just fine.

Any clues appreciated.

Thanks
Manpreet

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: