Here's a ~/.vimrc that opens up the current directory when no files are given as arguments.
if argc() ==# 0
silent execute 'edit .'
endif
vim has two functions argv and argc which mimic the behavior of the parameters conventionally called argv and argc in C, except both are functions.
argc returns the number of positional parameters in the argument list.
vim will helpfully remove all the command line arguments, so with the above ~/.vimrc, for example, vim -y will still open the current working directory.
The other example that I gave earlier today, browse oldfiles is more complex.
if argc() ==# 0
silent execute 'browse oldfiles'
endif
The above .vimrc opens an empty list.
If we remove the silent, giving us
if argc() ==# 0
execute 'edit .'
endif
then we see the following error message.
No old files.
Press ENTER or type command to continue
This makes me think that my ~/.vimrc is executing too early, before the oldfiles are actually parsed.
I don't have any idea how to delay the evaluation of my ~/.vimrc though.
browse oldfilesto run by default (I think the oldfiles list is populated after your vimrc runs), but that probably belongs in another question. Your answer is very good though and I've accepted it. – Greg Nisbet Nov 07 '23 at 05:54browse oldwe will have a look. – Vivian De Smedt Nov 07 '23 at 07:24