1

I have directory ~/temp with log files. This directory contains another directory ~/temp/aaa that also contains several logs. I would like to open all log files at once. I do

vim -p *

It opens files in current directory and that is fine, but it also opens directory aaa with list of files in content ant I would like to omit it. Also no files are opened in aaa directory. I could add /aaa/* into command, but his is not good since directory name might change and I would like to have more universal command.

How to enumerate all files in directory and sub directory for vim?

1 Answer 1

0

You can use the following command which will open vim with tab for each file under the current directory:

vim -p `find -L . -type f -print`

Or the following command which will open all files in the current directory, and all files in all first-level-of-sub-directories of the current directory

vim -p ./* ./*/*

The above command is based on running vim -p together with example from similar answer which can be found here


A few (modified) examples from the extended answer will open vim for every file under the current directory, and once vim will be closed, will open vim again for the next file, etc:

find . -xtype f -exec vim {} \;

Or

find -L . -type f -exec vim {} \;
3
  • Is that globstar and extglob in the last one? If so you should mention how to enable those options.
    – dessert
    Jan 31, 2018 at 13:59
  • If your file names have spaces or special characters IIRC that find command needs altering, look at print0 flag, and possibly needs xargs.
    – pbhj
    Jan 31, 2018 at 14:52
  • @pbhj - Thanks for your comment, which is correct for the vim -p `find xxx -print` command! Note that: the two examples with find xxx -exec vim {} \l; works well even with filenames which includes spaces.
    – Yaron
    Jan 31, 2018 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .