Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open all files in a folder

Tags:

vim

Suppose you'd like to open all the files in your checkout folder under the /trunk subdirectory. Assume the files are called first.c second.r third.cpp. How can you open all the files into vim with a single command.

The obvious answer is the following

$ vim first.c second.r third.cpp

But can you do this more simply?

like image 517
Milktrader Avatar asked Jun 20 '10 23:06

Milktrader


People also ask

Is there a way to open multiple files at once?

To select multiple files on Windows 10 from a folder, use the Shift key and select the first and last file at the ends of the entire range you want to select. To select multiple files on Windows 10 from your desktop, hold down the Ctrl key as you click on each file until all are selected.

How do I click all files in a folder?

Click the first file or folder, and then press and hold the Ctrl key. While holding Ctrl , click each of the other files or folders you want to select.

How do I open all files at the same time?

Click in the Shortcut key box on the Shortcut tab. Then press a keyboard key to set up a Ctrl + Alt shortcut for it. Click the Apply and OK buttons. Thereafter, press the Ctrl + Alt hotkey for the batch file to open its file list.


6 Answers

To edit all files in the current folder, use:

vim *

To edit all files in tabs, use:

vim -p *

To edit all files in horizontally split windows, use:

vim -o *
like image 93
linuscl Avatar answered Oct 11 '22 21:10

linuscl


Sounds like you're on linux or some Unix variant. Using the asterisk gets you all files in the current folder:

$ vim *
like image 40
desau Avatar answered Oct 11 '22 21:10

desau


In addition to the answers given above, I'd like to point out that you can also do that from inside vim itself using

:args * 

which sets the arglist to be the name of the files in the directory, and then you can display them in tabs with :tab all (or you can use :argdo tabe).

like image 39
Ash Avatar answered Oct 11 '22 21:10

Ash


The other answers will not work if you have subdirectories. If you need to open all files in all subdirectories you can use command substitution:

vim `find . -type f`

If you want to ignore files in subdirectories write:

vim `find . -type f -depth 1`

You can, of course, get as fancy as you want using the find command.

like image 24
durum Avatar answered Oct 11 '22 20:10

durum


Edit all files using a given pattern:

vim `find . -name "*your*pattern*here*"`

Super useful when I do this:

vim `find . -name "*.go"`
like image 29
superarts.org Avatar answered Oct 11 '22 21:10

superarts.org


durum's answer is incomplete. To open all files in the directory without opening files in subdirectories, use this:

vim `find . -maxdepth 1 -type f`
like image 31
hernytan Avatar answered Oct 11 '22 20:10

hernytan