Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open all files (including hidden) in vi

Tags:

vim

load

I have a file structure like so

/foo/bar/
├── .foo.cfg
├── foo.cfg
├── foo.data
├── foo.py
├── .svn
│   ├── ...
│   ├── ...
│   └── ...
├── .
└── ..

I want to open all of the hidden and non hidden files into vim. I could do it manually like so

vi .foo.cfg foo.cfg foo.data foo.py

but that doesn't work when there are 100+ files. I have also tried the following with no success

#hidden files not loaded
vi *

#Includes folders and '.' and '..'
vi * .*

#loads files one at a time
for i in `ls -a` ; do vi $i; done;

#loads files one at a time
find . -name "*" -type f -maxdepth 1 -exec vi {} ";"
like image 639
puk Avatar asked Feb 23 '23 05:02

puk


1 Answers

The following should work:

find . -maxdepth 1 -type f -exec vi {} +

From the find man page:

   -exec command {} +  

This variant of the -exec option runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way that xargs builds its command lines. Only one instance of ’{}’ is allowed within the command. The command is executed in the starting directory.

like image 71
Andrew Clark Avatar answered Mar 06 '23 02:03

Andrew Clark